Is my linked above correct, i got problem deleting nodes , any1 got any idead how should I do it. Anyway I not sure if i miss anything on the linked list i forgot to add.Some1 help me. Thank you. I am trying to delete the third nodes.Code:#include <iostream> using namespace std; struct nodeType { int info; nodeType * link; }; void main(void) { nodeType * first, * last, *newNode, * current ,*previous; first = last = newNode = NULL; //int num; first = NULL; last = NULL; cout << "Building a linked list: " << endl; newNode = new nodeType; newNode -> info = 5; newNode -> link = NULL; cout << "My first node is " <<newNode -> info << endl; first = last = newNode; newNode = new nodeType; newNode -> info = 15; newNode -> link = NULL; cout << "My second node is " <<newNode -> info << endl; last->link = newNode; last = newNode; newNode = new nodeType; newNode -> info = 10; newNode -> link = NULL; cout << "My third node is " <<newNode -> info << endl; last->link = newNode; last = newNode; newNode = new nodeType; newNode -> info = 22; newNode -> link = NULL; cout << "My fourth node is " <<newNode -> info << endl; last->link = newNode; last = newNode; cout << "End of building a linked list: " << endl; cout << "Transvering " << endl; current = first; cout << "Transvering through the first node" << endl; cout << current-> info << endl; cout << "Transvering thorugh the second node" << endl; current = current->link ; cout << current -> info << endl; cout << "Transvering through the third node" << endl; current = current-> link; cout << current -> info << endl; cout << "Transvering through the fourth node" << endl; current = current-> link; cout << current -> info << endl; cout << "Transvering through the last node" << endl; if (current = last) { cout << "No transvering allowed: " << endl; } else { cout << current -> info << endl; } cout << endl; cout << "Transvering back to the first node: " << endl; current = first; cout << current -> info << endl; //Deleting third node cout << "Deleting third node from the link list" << endl; current = first; previous = first; previous ->link = previous ->link -> link; current = previous ->link; previous -> link = current->link; delete current; current = first; cout << current -> info << endl; current = current ->link->link; cout << current -> info << endl; current = current ->link->link->link; cout << current -> info << endl; system ("pause"); }



1Likes
LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.
