+1 vote
102 views
In double linked list organization, insertion and deletion of a record involves maximum modification of number of pointers respectively ___________________
asked in DS | 102 views
4 nd 2 resp.

See the code

P---------->Q------------->R

P,R are 2 nodes, and in 1st code we are inserting Q

q->next=p->next;
p->next=q;
q->prev=p->next->prev;
r->prev=q->next->prev;

p->next=p->next->next;
r->prev=r->prev->prev;

Here in this 2nd code P,Q, R are 3 nodes, and we want to delete Q from it.

just a simple example to understand the code :)

plzz explain little more.. i m nt getting u...
if you just talk about modification of existing pointers then it should be 2 for insertion.

@srestha, I think for delete purpose also we need to update 4 pointers.

Considering your example, ptrs modified as follow

1. p.next

2. r.prev

3. q.next = null // Dangling PTR

4. q.prev = null // Dangling Ptr

in insertion,Maximum number of modified Pointers=4

in deletion it is 2
answered by Veteran (20.4k points) 12 77 174