GATE CSE
First time here? Checkout the FAQ!
x
0 votes
125 views
To insert a node at the end of double linked list we need to modify two pointers right??But answer given is one pointer.
can someone clarify?
asked in Programming by Boss (8.6k points)  
edited by | 125 views

1 Answer

0 votes
Assume we have a pointer " LAST " which point to the last pointer

and we know LAST --> next = NULL

we create a new pointer called NEW and add it to end of LL

so we hv to modify following pointers :

LAST --> next = NEW

NEW  --> prev = LAST

NEW  --> next = NULL
answered by Loyal (3.2k points)  
ur approach is correct

but in made easy test series answer given is one only..

I think to insert at the end we are modifying only last->next = new which was null earlier

rest all ,we  are assigning not modifying.

new->next=null and new->prev=last both are assignment instead of modification.
if it like , how many links are modified in only given LL , i mean if we dont consider NEW node links
ya...because new node is not there in the list and we are just assiging the value to its data and link part then inserting it at the end so it is added not modified.

if something is already there and we are changing then we are are modifying the pointer.

So, only one pointer is modified which is last->link
I agree with @cse23


Top Users Sep 2017
  1. Habibkhan

    6826 Points

  2. Arjun

    2310 Points

  3. Warrior

    2302 Points

  4. nikunj

    1980 Points

  5. A_i_$_h

    1922 Points

  6. manu00x

    1750 Points

  7. Bikram

    1744 Points

  8. SiddharthMahapatra

    1718 Points

  9. rishu_darkshadow

    1694 Points

  10. makhdoom ghaya

    1690 Points


26,033 questions
33,612 answers
79,660 comments
31,066 users