Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct nodeType
  6. {
  7. int info;
  8. nodeType *link;
  9. };
  10.  
  11. int main()
  12. {
  13. nodeType *head = new nodeType;
  14.  
  15. head->link = new nodeType;
  16. head->info = 17;
  17. cout << head->info << " " << head->link << endl;
  18. system("pause");
  19. head->link->link = new nodeType;
  20. head->link->info = 23;
  21. cout << head->link->info << " " << head->link->link << endl;
  22.  
  23. head->link->link->link = new nodeType;
  24. head->link->link->info = 50;
  25. cout << head->link->link->info << " " << head->link->link->link << endl;
  26.  
  27. head->link->link->link->link = NULL;
  28. //the last link
  29. cout << "Last: " << head->link->link->link->link << endl;
  30.  
  31.  
  32. //Insert
  33. //nodeType *s, *t, *insertNode = new nodeType;
  34. //insertNode->info = 100;
  35. //s = head;
  36. //t = head->link;
  37. //cout << "s and t : " << s << " " << t << endl;
  38.  
  39. //s->link = insertNode;
  40. //insertNode->link = t;
  41. //cout << "s and t : " << " " << s->link << " " << t->link << endl;
  42. //
  43. //delete
  44. //s = s->link;
  45. //cout << "New Numbers Info: " << s->info << " " << s->link->info << " " << s->link->link->info << endl;
  46.  
  47.  
  48. nodeType *current;
  49. current = head;
  50.  
  51. cout << "current: " << current->info << " " << current->link << endl;//17
  52.  
  53. current = current->link;//go to the next node
  54. cout << "current: " << current->info << " " << current->link << endl;//23
  55.  
  56. current = current->link;//go to the following node
  57. cout << "current: " << current->info << " " << current->link << endl;//50
  58.  
  59. //the last link
  60. cout << "current Last: " << current->link->link << endl;
  61.  
  62.  
  63.  
  64. nodeType *p;
  65. p = head;
  66. for (int i = 0; i < 4; i++)
  67. {
  68. cout << "p: " << p->info << " " << p->link << endl;
  69. p = p->link;//go to the next node
  70. }
  71. //the last link
  72. cout << "p Last: " << p->link << endl;
  73.  
  74. cout << "NewNode" << endl;
  75. nodeType *newNode;
  76. newNode = head;
  77. cout << head->link << endl;
  78. cout << newNode->link << endl;
  79.  
  80. while (newNode != NULL)
  81. {
  82. cout << "newNode: " << newNode->info << " " << newNode->link << endl;
  83. /* if(newNode->link == NULL)
  84. cout << "Null" << endl; */
  85. newNode = newNode->link;
  86. }
  87.  
  88.  
  89.  
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement