c++ - Three elements in one node of a linked list -


i trying understand linked lists , having difficult time. want put 3 elements in node , print multiple nodes out. however, able print first element of node. example: input: 1, 2, 3 output: 1 null

struct node {     int intx, inty, intz;     struct node *p; }  class linked { public:     node* create_node(int first, int second, int third);     int intx, inty, intz;     void insert();     void display(); }  main() {     linked sl;     sl.insert();     sl.display(); }  node *linked::create_node(int first, int second, int third) {     intx = first;     inty = second;     intz = third;     struct node *temp, *p;     temp = new (struct node);     if (temp == null)     {         cout << "not able complete";     }     else     {         temp->intx = first, inty = second, intz = third;         temp->next = null;         return temp;     } }  void linked::insert() {     int intx, inty, intz;     cout << "enter first element node: ";     cin >> intx;     cout << "enter second element node: ";     cin >> inty;     cout << "enter third element node: ";     cin >> intz;     struct node *temp, *s;     temp = create_node(intx, inty, intz);     if (start == null)     {         start = temp;         start->next = null;     }     else     {         s = start;         start = temp;         start->next = s;     }     cout << "element inserted." << endl; }  void linked::display() {     struct node *temp;     cout << "elements of list are: " << endl;     while (temp != null)     {         cout << temp->intx, inty, intz;         temp = temp->next;     }     cout << "null" << endl; } 

temp-> intx = first, inty = second, intz = third; 

separating things commas doesn't think here. should use 3 statements , have include temp-> in each:

temp->intx = first; temp->inty = second; temp->intz = third; 

if want use comma operator, can, still need temp-> on 3 assignments.

similarly, commas you're using in display don't want

cout<< temp->intx, inty, intz; 

should be

cout<< temp->intx << "," << temp->inty << "," << temp->intz; 

or depending on how want formatted


Comments