Блог пользователя vsanjay_nitdgp

Автор vsanjay_nitdgp, история, 9 лет назад, По-английски

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.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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;
...