Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct nodeType
- {
- int info;
- nodeType *link;
- };
- int main()
- {
- nodeType *head = new nodeType;
- head->link = new nodeType;
- head->info = 17;
- cout << head->info << " " << head->link << endl;
- system("pause");
- head->link->link = new nodeType;
- head->link->info = 23;
- cout << head->link->info << " " << head->link->link << endl;
- head->link->link->link = new nodeType;
- head->link->link->info = 50;
- cout << head->link->link->info << " " << head->link->link->link << endl;
- head->link->link->link->link = NULL;
- //the last link
- cout << "Last: " << head->link->link->link->link << endl;
- //Insert
- //nodeType *s, *t, *insertNode = new nodeType;
- //insertNode->info = 100;
- //s = head;
- //t = head->link;
- //cout << "s and t : " << s << " " << t << endl;
- //s->link = insertNode;
- //insertNode->link = t;
- //cout << "s and t : " << " " << s->link << " " << t->link << endl;
- //
- //delete
- //s = s->link;
- //cout << "New Numbers Info: " << s->info << " " << s->link->info << " " << s->link->link->info << endl;
- nodeType *current;
- current = head;
- cout << "current: " << current->info << " " << current->link << endl;//17
- current = current->link;//go to the next node
- cout << "current: " << current->info << " " << current->link << endl;//23
- current = current->link;//go to the following node
- cout << "current: " << current->info << " " << current->link << endl;//50
- //the last link
- cout << "current Last: " << current->link->link << endl;
- nodeType *p;
- p = head;
- for (int i = 0; i < 4; i++)
- {
- cout << "p: " << p->info << " " << p->link << endl;
- p = p->link;//go to the next node
- }
- //the last link
- cout << "p Last: " << p->link << endl;
- cout << "NewNode" << endl;
- nodeType *newNode;
- newNode = head;
- cout << head->link << endl;
- cout << newNode->link << endl;
- while (newNode != NULL)
- {
- cout << "newNode: " << newNode->info << " " << newNode->link << endl;
- /* if(newNode->link == NULL)
- cout << "Null" << endl; */
- newNode = newNode->link;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement