vsanjay_nitdgp's blog

By vsanjay_nitdgp, history, 9 years ago, In English

recently i wrote a program on doubly linbked list.....this is my code

http://ideone.com/XLSln7

i coulod able to put number at any position except at end.....could you pls tell whats wrong in this code.

THIS WAS MY QUESTION ..BUT LATER I SAW THE CODE TWICE ....AND GOT THE ERROR..

i got it...in doubly linked list.....when you are inserting a noe at the end....see that you are not using thsi step...

"temp1->next->prev=temp1;"

so....take a global variable 'l' which keeps track of length of list....when list length is equal to your inserting position ,dont use that line....

check modified code below

http://ideone.com/mwEiyp

hope this helps for beginners of linked list.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I wonder why all Indian coders prefer to ignore last 20+ years of C++ development. Really, guys

node(long long data): data(data) {}
...
node templ(x);
...
head = &templ;
...