link list problem on basic concept

XV1oNL - Online C++ Compiler & Debugging Tool - Ideone.com this is the url of code i tried to make a link list with items adding at the end but whenever i enter a new element it does not show the previous one what is wrong in my code.

If you are adding at the end then why are you doing temp->next=head;head=temp;
if there is at least one item in list as you have checked head should not be changed;

Hi rahulsup,

if you want to insert at last then you should use a pointer which point to last node like we use head to point first node

otherwise we have to iterate upto last node to add new node next to it

every time when we add new node then we point that as last node and again when we add new node then we point that new node as last node means at every insertion value of last node changes because we are inserting at last obviously

here you code goes UPgPWv - Online C++0x Compiler & Debugging Tool - Ideone.com :slight_smile:

First of all,in your code you are adding element to the head(not at the end)

Secondly,Considering that you are adding element at the head node,your code is working fine, there’s no problem with it.

It is showing all the items. Check carefully :slight_smile:

@ayushkapadia i am writing temp->next=NULL; then modifying the head whats wrong in that?

thanks admin for help