I am now doing the doubly linked list. I not sure what should I do to transverse and print the values using cout. Because, doubly linked list got 2 linking to the next nodes and I am totally stucked on what to do.Code:#include <iostream> using namespace std; struct dNode { int info; dNode *next; //link to next node dNode *back; //link to previous node }; void main(void) { dNode *head, *tail, *newNode *current; head = tail = newNode = NULL; newNode = new dNode; newNode->info = 55; newNode->next = NULL; newNode->back = NULL; cout << "My first node is " << newNode -> info << endl; head = tail = newNode; newNode = new dNode; newNode->info = 514; newNode->next = NULL; newNode->back = NULL; cout << "My second node is " << newNode -> info << endl; tail->next = newNode; newNode = new dNode; newNode->info = 27; newNode->next = NULL; newNode->back = NULL; cout << "My third node is " << newNode -> info << endl; tail->next = newNode; newNode = new dNode; newNode->info = 35; newNode->next = NULL; newNode->back = NULL; cout << "My fourth node is " << newNode -> info << endl; tail->next = newNode; cout << "End of building a linked list: " << endl; //end of building a linked list cout << "Transvering " << endl; //start to transverse current = head; //set current pointer to the first system ("pause"); }



1Likes
LinkBack URL
About LinkBacks


