nomadass
March 14th, 2003, 02:57 AM
this program is used to reverse the link list using a recursive way.
//Hi, sir:
//about tut 6. question 3, my solution is:
void recursiveReverse(Node* &n){
node *temp1 = n, *temp2 = n;
static node* temp3 = n->getNext(), *temp4 = n;
//temp1, temp2 temp3 will traver the linked list;
// temp4 holds the head;
temp2 = temp3;
temp3 = temp3->getNext();
if (temp3 == NULL){
temp2->setNext(temp1);
temp4->setNext(0);
temp3 = temp4;
}
temp2->setNext(temp1);
recursiveReverse(temp2);
}
//this is different from the tutor's answer.
//and he said this one will not work;
//I wonder why? can you piont out for me
//what is more, he said the special case
//that only one node or two nodes, I think
//this solution no need consider that, for
// they are aready included by , I think
//Hi, sir:
//about tut 6. question 3, my solution is:
void recursiveReverse(Node* &n){
node *temp1 = n, *temp2 = n;
static node* temp3 = n->getNext(), *temp4 = n;
//temp1, temp2 temp3 will traver the linked list;
// temp4 holds the head;
temp2 = temp3;
temp3 = temp3->getNext();
if (temp3 == NULL){
temp2->setNext(temp1);
temp4->setNext(0);
temp3 = temp4;
}
temp2->setNext(temp1);
recursiveReverse(temp2);
}
//this is different from the tutor's answer.
//and he said this one will not work;
//I wonder why? can you piont out for me
//what is more, he said the special case
//that only one node or two nodes, I think
//this solution no need consider that, for
// they are aready included by , I think