Hi all, I'm in need of some help.
I made a simple linked list, but when I try to traverse through it in reverse, I keep getting a "exception error"...can someone shed any light on where I'm going wrong?
Please and thank you
Code:struct Node { int Data; Node *next; Node *prev; }; int main() { Node *head = new Node; Node *current, *tail; current = head; tail = head; cout << current << endl; cout << tail << endl; cout << head << endl; //all current,head,and tail point to the same location in the heap //NOW COMES THE HARD PART current->Data = 0; current->prev = NULL; //the head's previous is now point to null for(int i = 1; i <= 10; i++) { current->next = new Node; current->next->Data = i; current = current->next; tail = current->prev; tail = current; } current->next = NULL; while(tail != NULL) { cout << tail->Data << endl; tail = tail->prev; //why is tail not being able to capture the previous location? } cout << "data in tail: " << tail->Data << endl; //cout << tail->prev->Data << endl; //at this line, I receive compile error //a bunch of question marks pop up //why is tail not being able to hold the previous node's address???



LinkBack URL
About LinkBacks


