the method doesnt work.im compiling in Turbo c++.
here is the code :
void linklist :: add_at_first()
{ node *temp;
temp = new node();
temp -%26gt;prev=temp -%26gt;next=NULL;
cout %26lt;%26lt;"Please Enter A Number :"%26lt;%26lt; endl;
cin %26gt;%26gt; temp -%26gt; num;
if(first ==last==NULL)// if the list is empty
{ first = last=temp;
}
else
{
temp -%26gt; next = first;
first = temp;
}
}
when i use set watch to see the values of the elements,it says :"undefined symbol "the item i selected.""
I'm implementing a doubly linklist in c++.im trying to add a node at the beginning of the doubly linklist,but
shouldn't the last part of your code look more like...
...
else
{
first-%26gt;prev=temp;
temp-%26gt;next=first;
first=temp;
}
}
You did say doubly linked correct? The way you have it now, you correctly set temp-%26gt;next to point to the first node but you never tell the first node to point back to the newly created temp.
forsythia
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment