0
void Display(Productptr t)
{
    Productptr g;
    g=t;
    if(t==NULL)
        cout<<"The list is empty."<<endl;
    else
    {
    cout<<"Code\tDescription\tPrice\n";
    cout<<"====\t===========\t=====\n";
        while(g!= NULL)
        {       
            cout<<g->code<<"\t"
                <<g->description<<"\t\t"
                <<g->price<<endl;
        }
        cout<<"End of the list"<<endl;
    }
    system("pause");
}

This code give me problem.
When I show 1st time is ok.
After 1st time I add something or delete something it will shown repeated 1st node that I insert.After that I cannot get back the normal already.
Any one can explain and solve it??
Text file I also get the same problem.
When I add or delete something in function cannot work normal agian.
The picture down show my problem.

Edited by Dani: Fixed formatting

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Jakiro
0

The loop that begins on line 11 of the code you posted: where in that loop do you increment g to point to the next node in the linked list? Don't you want something like this?

while(g != NULL)
{
  ... <snip>
   g = g->next;
}

Also I don't see any need to save the original parameter pointer because it is never used again in that function. You could just delete g and use t instead.

0

I solve my problem already.
Thank you.
I miss up one g=g->Next;
so i alway get back the samething.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.