Loosing one node in my program
Write your question here.
When I run my program, the node with info=30 gets lost. Please help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
Put the code you need help with here.
#include <iostream>
using namespace std;
int main() {
using namespace std;
struct nodeType
{
int info;
nodeType *link;
} ;
typedef nodeType *nodePtr;
nodePtr ptr, list;
list = new nodeType;
list->info = 20;
ptr = new nodeType;
ptr ->info = 28;
ptr->link = NULL;
list->link = ptr;
ptr = new nodeType;
ptr->info = 30;
ptr->link = list;
list = ptr;
ptr = new nodeType;
ptr->info = 42;
ptr->link = list->link;
list->link = ptr;
while(ptr != NULL)
{
cout << ptr->info << endl;
ptr = ptr->link;
}
}
|
Topic archived. No new replies allowed.