hey I decided to compile your code and I think you had a logical mistake in the insert function. I wrote it in c++, but I think you won't have much problem in porting it to c.
when I use this with the display function I posted above, it works perfectly fine.Code:void InsertItem(currency **list) { currency *temp; cout<<"Enter name: "; gets(temp->name); cout<<"Enter code: "; gets(temp->code); cout<<"Enter value: "; cin>>temp->value; temp->number=++cnt; temp->next=*list; *list=temp; }
Note that this function is for insertion at the front. For insertion at the rear, you just have to do the following:
And one more thing, I think allocating a fixed memory space for the nodes using malloc or new would result in better memory management.Code:curreny *cur; cur=*list; while(cur->next!=NULL) cur=cur->next; //this finds out the last node cur->link=temp; temp->link=NULL;




Reply With Quote