0% found this document useful (0 votes)
23 views

Linked List Data Structure Operations and Its Pseudocodes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Linked List Data Structure Operations and Its Pseudocodes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

LINKED LIST DATA STRUCTURE

OPERATIONS AND ITS


PSEUDOCODES
Singly Linked List

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

If(current == null) then


{
Print(“the given position is out of range”);
Return;
}
Set new_node.next to current.next;
Set current.next to new_node;
}

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

For(int i = 0; current != null && i <position -1; i++){


Set current to current.next
}
If(current == null){
If(tail == null){
Set tail to new_node
}

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
}

Set current.next to new_node


}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy