c++ - Print Index of a multilist -


i trying print index of multi linked list. each node has 2 elements- warehouse number , tool number. printing tools in each warehouse. having problem iterating correctly through list.

i not getting correct values , having trouble finding problem in method.

struct node {     int warehousenumber;     int toolnumber;     struct node *n; }  void showwarehouses() {     int tempvalue;     bool flag = false;     struct node *s;     s = start;     if (start == null)       {         cout<<"unable";         return;     }     s->warehousen = tempvalue;     cout<<"warehouse "<<tempvalue<< ": tool ";     while(s != null)         {             if (s->warehousen == tempvalue)             {             flag = true;             cout<< s->tooln <<" ";             s = s->next;             }     } } 

you haven't assigned values tempvalue causes undefined behavior. read this post.

also based on have in struct node , code, think can have picture in program , want print them.

lined list

so top off write code:

void showwarehouses() {     int tempvalue=1;     bool flag, cont;     struct node *s;     if (start == null)     {         cout << "unable";         return;     }      cont = true;     while (cont)     {         cont = false, flag = false;         s = start;         while (s)         {             if (s->warehousen == tempvalue){                 cont = true;                 if (!flag){                     cout << "warehouse " << tempvalue << ": tool ";                     flag = true;                 }                 cout << s->tooln << " ";             }             s = s->next;         }         cout << endl;         tempvalue++;     } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -