954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

linked list

Hi
I try to fill linked list with names. I have one error could anyone fix it.

#include<iostream>
#include<conio.h>
#define MaxSize 30
using namespace std;

struct Node
{
  char name[MaxSize];
  Node* link;
};
class Q
{
  public:
         void get_input(char array[]);
         void print_input();
  private:
          Node* head;
          void display(Node* );
};
int main()
{
  Q q;
  cout<<"We are goig to fill an linked list with nodes, and then switch the :";
  cout<<"order between them, we will pick which wat words are go where? ";
  q.get_input("Joe");
  q.get_input("Marry");
  q.get_input("Brat");
  q.get_input("Smith");
  q.get_input("Guy");
  q.get_input("Josh");
  q.print_input();
  
  getch();
  return 0;
}
void Q::get_input(char array[])
{
  Node* temp;
  temp=new Node;
  temp->name=array[];
  temp->link=head;
  head=temp;
}
void Q::print_input()
{
  cout<<"The output is : ";
  display(head);
}
  
void Q::display(Node* head)
{
 if (head=NULL)
 return ;
 else
 cout<<head->name<<" ";
 display(head->link);
}


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

mauro21pl
Junior Poster in Training
66 posts since Jan 2007
Reputation Points: 20
Solved Threads: 0
 

please re-read my answer to your previous thead here . I already answered this question.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

right
Got it. Fix the error but there is something else with it. Look at the code. Some trouble with nodes I believe

#include<iostream>
#include<conio.h>
#define MaxSize 30
using namespace std;

struct Node
{
  char name[MaxSize];
  Node* link;
};
class Q
{
  public:
         void get_input(char array[]);
         void print_input();
  private:
          Node* head;
          void display(Node* );
};
int main()
{
  Q q;
  cout<<"We are goig to fill an linked list with nodes, and then switch the :";
  cout<<"order between them, we will pick which wat words are go where? ";
  q.get_input("Joe");
  q.get_input("Marry");
  q.get_input("Brat");
  q.get_input("Smith");
  q.get_input("Guy");
  q.get_input("Josh");
  q.print_input();
  
  getch();
  return 0;
}
void Q::get_input(char array[])
{
  Node* temp;
  temp=new Node;
  strcpy(temp->name,array);
  temp->link=head;
  head=temp;
}
void Q::print_input()
{
  cout<<"The output is : ";
  display(head);
}
  
void Q::display(Node* head)
{
 if (head=NULL)
 return ;
 else
 cout<<head->name<<" ";
 display(head->link);
}
mauro21pl
Junior Poster in Training
66 posts since Jan 2007
Reputation Points: 20
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You