linked list

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

Join Date: Jan 2007
Posts: 67
Reputation: mauro21pl is an unknown quantity at this point 
Solved Threads: 0
mauro21pl mauro21pl is offline Offline
Junior Poster in Training

linked list

 
0
  #1
Aug 15th, 2007
Hi
I try to fill linked list with names. I have one error could anyone fix it.

  1.  
  2. #include<iostream>
  3. #include<conio.h>
  4. #define MaxSize 30
  5. using namespace std;
  6.  
  7. struct Node
  8. {
  9. char name[MaxSize];
  10. Node* link;
  11. };
  12. class Q
  13. {
  14. public:
  15. void get_input(char array[]);
  16. void print_input();
  17. private:
  18. Node* head;
  19. void display(Node* );
  20. };
  21. int main()
  22. {
  23. Q q;
  24. cout<<"We are goig to fill an linked list with nodes, and then switch the :";
  25. cout<<"order between them, we will pick which wat words are go where? ";
  26. q.get_input("Joe");
  27. q.get_input("Marry");
  28. q.get_input("Brat");
  29. q.get_input("Smith");
  30. q.get_input("Guy");
  31. q.get_input("Josh");
  32. q.print_input();
  33.  
  34. getch();
  35. return 0;
  36. }
  37. void Q::get_input(char array[])
  38. {
  39. Node* temp;
  40. temp=new Node;
  41. temp->name=array[];
  42. temp->link=head;
  43. head=temp;
  44. }
  45. void Q::print_input()
  46. {
  47. cout<<"The output is : ";
  48. display(head);
  49. }
  50.  
  51. void Q::display(Node* head)
  52. {
  53. if (head=NULL)
  54. return ;
  55. else
  56. cout<<head->name<<" ";
  57. display(head->link);
  58. }

the error I have is:
44 C:\Documents and Settings\mauro\Desktop\c++\nodes- read names switched them around and display them.cpp expected primary-expression before ']' token
thx
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: linked list

 
0
  #2
Aug 15th, 2007
please re-read my answer to your previous thead here. I already answered this question.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 67
Reputation: mauro21pl is an unknown quantity at this point 
Solved Threads: 0
mauro21pl mauro21pl is offline Offline
Junior Poster in Training

Re: linked list

 
0
  #3
Aug 15th, 2007
right
Got it. Fix the error but there is something else with it. Look at the code. Some trouble with nodes I believe

  1.  
  2. #include<iostream>
  3. #include<conio.h>
  4. #define MaxSize 30
  5. using namespace std;
  6.  
  7. struct Node
  8. {
  9. char name[MaxSize];
  10. Node* link;
  11. };
  12. class Q
  13. {
  14. public:
  15. void get_input(char array[]);
  16. void print_input();
  17. private:
  18. Node* head;
  19. void display(Node* );
  20. };
  21. int main()
  22. {
  23. Q q;
  24. cout<<"We are goig to fill an linked list with nodes, and then switch the :";
  25. cout<<"order between them, we will pick which wat words are go where? ";
  26. q.get_input("Joe");
  27. q.get_input("Marry");
  28. q.get_input("Brat");
  29. q.get_input("Smith");
  30. q.get_input("Guy");
  31. q.get_input("Josh");
  32. q.print_input();
  33.  
  34. getch();
  35. return 0;
  36. }
  37. void Q::get_input(char array[])
  38. {
  39. Node* temp;
  40. temp=new Node;
  41. strcpy(temp->name,array);
  42. temp->link=head;
  43. head=temp;
  44. }
  45. void Q::print_input()
  46. {
  47. cout<<"The output is : ";
  48. display(head);
  49. }
  50.  
  51. void Q::display(Node* head)
  52. {
  53. if (head=NULL)
  54. return ;
  55. else
  56. cout<<head->name<<" ";
  57. display(head->link);
  58. }
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: 1490 | Replies: 2
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC