Linked List Operations algorithm

In computer science, we use a group of nodes to represent sequence data. It's a data structure operation. The link list is a way of storing data in a sequence and use those data easily. This allows us to pick or delete data in a specific location of the list.


Linked List Operations algorithm
Linked List operation

Link List:

  1. Singly Link List 
  2. Doubly Link List
  3. Circular Link List

Link List Operations: 

  • Pseudo-code for insert at Beginning
  • Pseudo-code for insert at End
  • Pseudo-code for delete from Beginning
  • Pseudo-code for delete from End
  • Pseudo-code for insert at Kth position of the list
  • Pseudo-code for delete from Kth position of the list
  • Pseudo-code for search data in the list

Singly Link List:

Singly Link List contains a data find and also a tail to point the next data field or node.

Linked List Operations algorithm
Singly Link List

Doubly Link List:

 Doubly Link List contains a head, a data find, and also a tail to point the next data field or node.

Doubly Link List
 Doubly Link List

 Circular Link List:

In the Circular Link List, the last tail point to the first node's head. If we do like this, it's called a circular linked list otherwise it's called linear or open list.

Circular Link List
Circular Link List

 Link List Operations

1.  Pseudo-code for Insert at Beginning

Pseudo-code for Insert at Beginning
Pseudo-code for Insert at Beginning
getcell(m) //here m is a new cell containing data 1
m -> data = 1
m -> link = head
head = m

2. Pseudo-code for insert at End


Linked List Operations algorithm
Pseudo-code for insert at End
getcell(m) //here m is new cell containing data 9
Linked List Operations algorithm
Pseudo-code for insert at End
while(head->link != NULL)
head = head-> link

m-> link = NULL
m->data = 8
head->link = m

3. Pseudo-code for delete from Beginning

Linked List Operations algorithm
Pseudo-code for delete from Beginning
 temp = head
head = head->link
free(temp)

 4. Pseudo-code for delete from End

 Before deletion process:

Linked List Operations algorithm
Pseudo-code for delete from End(before)
temp = head
while(head->link != NULL)
{
temp = head
head = head->link
}

Linked List Operations algorithm
Pseudo-code for delete from End(before)
temp->link = NULL
free(head)

After Deletion process:

Linked List Operations algorithm
Pseudo-code for delete from End(after deletion)

 5. Pseudo-code for insert at Kth position of the list

 
Linked List Operations algorithm
insert at Kth position of the list

getcell(m) //we will insert in pos=3

Linked List Operations algorithm
insert at Kth position of the list

pos = k
for(i=1; i<=pos-2; i++)
head = head->link

temp = head->link
head->link = m
m>link = temp

6. Pseudo-code for delete from Kth position of the list

 Before deletion process:

Linked List Operations algorithm
delete from Kth position of the list(before)

for(i=1; i<=pos-2; i++)
head = head->link
temp = head->link
Linked List Operations algorithm
delete from Kth position of the list(before)

head->link = temp->link
free(temp)

After Deletion process:

 
Linked List Operations algorithm
delete from Kth position of the list(after deletion)

 7. Pseudo-code for search data in list

 
Linked List Operations algorithm
Pseudo-code for search data in list

 let key = 7
found = false
while(head->link !=Null && found == false)
{
if(head->data == key)
found = true

else
head = head->link
}
if(found == true) //search key found
else Not found
So, you can now try to write some code using a linked list.
Happy Coding

0/Post a Comment/Comments