The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
141 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 (9k points)
edited by | 141 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.5k 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


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

29,156 questions
36,980 answers
92,147 comments
34,822 users