Linked List Data Structure Operations and Its Pseudocodes
Linked List Data Structure Operations and Its Pseudocodes
OPERATIONS
-Creating Node
-Append/Add to Last
-Insert/Add to Start
-Insert at
-Delete
-Search
Creating Singly Linked List Node
Node{
Datatype data; //Declare a variable base on the specification
Node next; //Reference to the next node
}
Append/Add to Last
Append(new-data)
{
Declare new_node as node
new_node.data = new data
new_node.next = Null
If(head==null)
{
Set head to new_node
}
Else
{
Set last to head
while (last.next != null)
{
Set last to last.next
}
Set last.next to new_node
}
}
Insert/Add to Start
Insert_start(new_data)
{
Declare node new_node;
Set new_node.data to new_data;
Set new_node.next to head;
Set head to new_node;
}
InsertAt
InsertAt(position, new_data)
{
Declare node new_node;
Set new_node.data to new_data;
If(position == 1) then
{
Set new_node.next to head;
Set head to new_node;
End
}
Set current to head;
For(int i = 1; i < position-1 && current != null; i++) then
{
Set current to current.next;
}
Delete
Delete(position){
If position = 1
{
Set head to head.next
}
else
{
Set n to head;
Set del = null;
for(int i=1; i < position-1 ; i++)
{
n = n.next;
}
del = n.next;
n.next = del.next;
}
}
Search
Search (Data) {
Set current to head
While ( current.data !=(data) )
{
Set current to current.next
If (current=null)
{
Print “Data not Found”
Break;
}
}
If (current !=null)
{
Print “Data Found!”
}
}
LINKED LIST DATA STRUCTURE
OPERATIONS AND ITS
PSEUDOCODES
Doubly Linked List
OPERATIONS
-Creating Node
-Append/Add to Last
-Insert/Add to Start
-Insert at
-Delete
-Search
Creating Doubly Linked List Node
Node {
Datatype data //Declare a variable base on the specification
Node previous//Reference to previous node
Node next//Reference to next node
}
Append/Add to Last
Append(new_data){
If(head is null){
Set head.data to new_data
Set tail to head
}
Else{
Declare new_node as Node
Set new_node.data to new_data
Set new_node.previous to tail
Set tail.next to new_node
Set tail to new_node
}
}
Insert/Add to Start
insertAtBeginning(new_data){
Declare new_node as Node
Set new_node.data to new_data
If(head == null){
Set head to new_node
Set tail to new_node
}
Else{
Set new_node.next to head
Set head.prev to new_node;
Set head to new_node
}
}
InsertAt
insertAt(position, new_data){
if(position <= 0){
insertAtBeginning(new_data)
}
Set new_node to Node
Set new_node.data to new_data
Set current to head
Else{
Set new_node.prev to tail
Set tail.next to new_node
Set tail to new_node
}
}
Else{
Set new_node.next to current.next;
Set new_node.prev to current
If(current.next != null ){
Set current.next.prev to new_node
}
else{
set tail to new_node
}