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 (7.1k points)  
edited by | 101 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 (2.8k 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

0 votes
1 answer
asked in DS by shikharV Boss (5.1k points)   | 95 views
Top Users Jan 2017
  1. Debashish Deka

    7906 Points

  2. Habibkhan

    4736 Points

  3. Vijay Thakur

    4474 Points

  4. sudsho

    4318 Points

  5. saurabh rai

    4200 Points

  6. Arjun

    3638 Points

  7. Bikram

    3500 Points

  8. santhoshdevulapally

    3470 Points

  9. GateSet

    3228 Points

  10. Sushant Gokhale

    3116 Points

Monthly Topper: Rs. 500 gift card

18,944 questions
23,897 answers
20,213 users