Double linked list problem

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 35
Reputation: gazoo is an unknown quantity at this point 
Solved Threads: 0
gazoo gazoo is offline Offline
Light Poster

Double linked list problem

 
0
  #1
Apr 23rd, 2008
I have this program that suppost to ask user to select option:
[option]
a. Start a new list
b. Add a Node to the end of the list.
c. Add a Node to the beginning of the list.
d. Add a Node at a specified position in the list.
e. Walk the linked list, displaying all the "person" data.
f. Remove a Node at a specified position from the list. g. Delete the entire list.
[/option]
using double linked list, the code crashed with these errors:
[error]
error C2065: 'node' : undeclared identifier
error C2065: 'current' : undeclared identifier
error C2182: 'StartnewNode' : illegal use of type 'void'
fatal error C1903: unable to recover from previous error(s); stopping compilation
[error]

I don't see the problem, can anyone help me see what I did so wrong that it is failed so badely.

  1. #include<string>
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. //void InitializeNode();
  6. void StartnewNode(node *current);
  7. void add_node_at_end();
  8. void add_node_at_start(string new_name);
  9. void InsertNode(node *current, node *After);
  10. void displayNode(node *current);
  11. void RemoveNode(node *current);
  12. void DeleteAllNodes();
  13.  
  14. //linked list for the per_names
  15. struct Node
  16. {
  17. char* per_name[20];
  18. Node *prev;//pionter to the previous node
  19. Node *next;//pionter to the next node;
  20. };
  21.  
  22. node *current;
  23. noe *After;
  24. //create header node list
  25. current = new node;
  26. current->char* = per_name;
  27. current->next = NULL;
  28. current->prev = NULL;
  29.  
  30. Node *first;
  31. Node *last;
  32.  
  33.  
  34. int main()
  35. {
  36. for (int i=0; i < 5; i++)
  37. {
  38. //current = new NODE;
  39. current -> per_name = i;
  40. Start_a_newNode_list(current);
  41. }
  42. cout<<"\nThe contents of the original list are:\n";
  43.  
  44. for (current = first; current != NULL; current = current -> next)
  45. cout << "\t" << current -> per_name <<endl;
  46.  
  47. system ("pause");
  48. return 0;
  49. }
  50.  
  51. int MenuChoice;
  52.  
  53. InitializeNode();
  54. while(1)
  55. {
  56. cout << " 1. Start a_new list" << endl;
  57. cout << " 2. Add a Node to the end of the list" << endl;
  58. cout << " 3. Add a Node to the beginning of the list" << endl;
  59. cout << " 4. Add a Node at a specified position in the list" << endl;
  60. cout << " 5. displaying all the person data" << endl;
  61. cout << " 6. Remove a Node at a specified position from the list" << endl;
  62. cout << " 7. Delete the entire list" << endl;
  63. cout << " 8. Exit" << endl;
  64.  
  65. cout << "Enter your choice: ";
  66. cin >> MenuChoice;
  67.  
  68. if((MenuChoice < 0) && (MenuChoice > 8))
  69. {
  70. cout << "Invalid Choice" << endl;
  71. system("Pause Try Again");
  72. }
  73. else
  74. {
  75. switch(MenuChoice)
  76. {
  77. case 1: StartnewNode();
  78. break;
  79. case 2: add_node_at_end();
  80. break;
  81. case 3: add_node_at_start();
  82. break;
  83. case 4: InsertNode();
  84. break;
  85. case 5: displayNode();
  86. break;
  87. case 6: RemoveNode();
  88. break;
  89. case 7: DeleteAllNodes();
  90. break;
  91. case 8:
  92. exit(1);
  93. }
  94. }
  95. cin.get();
  96. }
  97.  
  98. return 0;
  99.  
  100. }
  101. // Add node at the begining of the list
  102. void add_node_at_start(string new_name)
  103. { // Declare a temporary pointer and move it to the start
  104. node *temp = current;
  105. while (temp->prev != NULL)
  106. temp = temp->prev;
  107. // Declare a new node and link it in
  108. node *temp2;
  109. temp2 = new node;
  110. temp2->name = new_name; // Store the new name in the node
  111. temp2->prev = NULL; // This is the new start of the list
  112. temp2->next = temp; // Links to current list
  113. temp->prev = temp2;
  114. }
  115.  
  116. // Add note at the end of the list
  117. void add_node_at_end ()
  118. { // Declare a temporary pointer and move it to the end
  119. node *temp = current;
  120. while (temp->next != NULL)
  121. temp = temp->next;
  122. // Declare a new node and link it in
  123. node *temp2;
  124. temp2 = new node;
  125. temp2->name = new_name; // Store the new name in the node
  126. temp2->next = NULL; // This is the new start of the list
  127. temp2->prev = temp; // Links to current list
  128. temp->next = temp2;
  129. }
  130. // Inserts a node into a specified location
  131. void InsertNode(node *current, node *After)
  132. {
  133. current->pNext = After->pNext;
  134. current->prev = After;
  135. if (After->next != NULL)
  136. After->next->prev = current;
  137. else
  138. last = current;
  139. After->next = current;
  140. }
  141.  
  142.  
  143. // Removes node from specified location
  144. void RemoveNode(node *current)
  145. {
  146. if (current->prev == NULL)
  147. first = current->next;
  148. else
  149. current->prev->next = current->next;
  150. if (current->next == NULL)
  151. last = current->prev;
  152. else
  153. current->next->prev = current->prev;
  154. }
  155.  
  156. // Deletes the entire list
  157. void DeleteAllNodes()
  158. {
  159. while (first != NULL)
  160. RemoveNode(first);
  161. }
  162.  
  163. // Now display each item in list
  164. for (current = first; pNode != NULL; current = current->next)
  165. {
  166. cout <<("\n", current->name);
  167. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 462
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 71
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: Double linked list problem

 
0
  #2
Apr 23rd, 2008
c++ is case sensitive
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1924 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC