First time here? Checkout the FAQ!
0 votes
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.2k points)  
edited by | 109 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 (3k 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

Related questions

Top Users Apr 2017
  1. akash.dinkar12

    3660 Points

  2. Divya Bharti

    2580 Points

  3. Deepthi_ts

    2040 Points

  4. rude

    1966 Points

  5. Tesla!

    1768 Points

  6. Debashish Deka

    1614 Points

  7. Shubham Sharma 2

    1610 Points

  8. Prashant.

    1492 Points

  9. Arjun

    1472 Points

  10. Arunav Khare

    1464 Points

Monthly Topper: Rs. 500 gift card

22,088 questions
28,063 answers
24,173 users