Log In
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?
in Programming
edited by

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

–1 vote
0 answers
Insertion at beginning and end ....both require theta(n) ?
asked Dec 21, 2017 in Programming Pawan Kumar 2 118 views
0 votes
2 answers
With regard to linked list, which of the following statement is false ? (A) An algorithm to search for an element in a singly linked list requires 0(n) operations in the worst case. (B) An algorithm for deleting the first element in a singly linked list ... linked list requires 0(n) operations. (D) An algorithm for deleting the middle node of a circular linked list requires 0(n) operations.
asked Sep 21, 2017 in DS rishu_darkshadow 209 views
0 votes
1 answer
The answer is 'd' will be printed. Can someone draw the linked list after the operations are performed. I think the second operation of the code doesn't bring in any change to the list. thanks in advance
asked Aug 23, 2018 in Programming Kalpataru Bose 144 views
0 votes
1 answer
Consider the C node fragment given below: Which of the following true about above code if input is given as linked list of n-element in which for each node memory is created in heap area? A. Compiles successfully but execution may result in dangling pointer. B. Compiles ... after free (p) in else part. I think answer should be C. Because the return type is int node* Can someone please confirm.
asked Jan 30, 2018 in Programming Rishabh Gupta 2 371 views