



Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!




Double-Linked List, Removal (Deletion) Operation.
There are four cases , which can occur while removing the node.
Note: If List has only one node , which is indicated by the condition, that the head points to the
same node as the tail , the removal is quite simple by set both head and tail to null.
Void Remove first
if (head = = null)
return ;
else n - - ; if (head. after = = null) head = null ; Tail = null ; else head = head. after ; head. before = null ;
Void Remove last
if (head = = null) return ; else n - - ; if (head. after = = null) head = null ; Tail = null ; else Tail = tail. before ; Tail. after = null ;
College of Information Technology / Software Department ……………………………………………………….. LEC. (^6) Data Structures / Second Class / 201 7 - 2018
// or it can be as if (head = = tail) or it can be as if (tail. before = = null)
// or it can be as if (head = = tail) or it can be as if (tail. before = = null)
Remove from Any Location if (head = = null) return ; else Input value of loc If (loc >=1 && loc <= n)
If (loc = = 1) Remove first() // call remove first function else if (loc = = n) Remove last() // call remove last function else n - - ; P = head ; For I = 1 ; I <= loc-2 ; I ++ p = p. after ;
p. after. after. before = p ; p. after = p. after. after ;
Else S.O.P (error value of loc);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
In single linked list, every node points to its next node in the sequence and the last node points NULL. But in circular linked list, every node points to its next node in the sequence but the last node points to the first node in the list.
H.W. // Write the function of inserting a node in circular linked list in any position.
P = head While p. next != head P = p. next //read v Node = new clink (v, head) P. next = node
P = head While p. next != head P = p. next //read v Node = new clink (v, head ) Head = node P. next = head
If head. next = = head
Head = null
Else
P = head While p. next. next != head P = p. next P. next = head
A- Write a function for deletion from circular linked list based on the position of a node.
B- Write a function for deletion from circular linked list based on the data value.