Docsity

Algoritmos para la eliminación de nodos en listas enlazadas doble y circular, Resúmenes de Informática y Tecnologías de la Información

Toggle sidebar
bg1
31
Remove Operation from Double Linked List
& Circular linked list
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
………………………………………………………..
Data Structures / Second Class / 2017-2018
LEC. 6
// 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)
pf3
pf4
pf5

Vista previa parcial del texto

¡Descarga Algoritmos para la eliminación de nodos en listas enlazadas doble y circular y más Resúmenes en PDF de Informática y Tecnologías de la Información solo en Docsity!

Remove Operation from Double Linked List

& Circular linked list

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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Circular Linked List

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.

Inserting At Beginning of the list

Inserting At Ending of the list

H.W. // Write the function of inserting a node in circular linked list in any position.

Delete From The Beginning of Circular Linked List

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

Delete From The End of Circular Linked List

If head. next = = head

Head = null

Else

P = head While p. next. next != head P = p. next P. next = head

H. W.//

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.

Examples Of Operations In Circular Doubly Linked List