Concatenate Two SLL Into One: Pseudo Code
Concatenate Two SLL Into One: Pseudo Code
Pseudo Code:-
Initialize the Singly linked list
struct Node{
int data;
struct Node *next;
};
Function Getdetails(Node **list):
Initialize a variable 'temp' of type Int
While(true):
Get value for 'temp'
If temp==0:
Break
Initialize 'ptr' of type Node*
Store temp in ptr->data
Insert (ptr,list)
Function Insert (Node *ptr, Node **listhead):
If (*listhead) equals NULL:
Make (*listhead) point to ‘ptr’
Else:
Store (*listhead)->next in ‘ptr->next’
Make (*listhead)->next as ‘ptr’
Function concat(Node *list1, Node *list2):
Initialize 'temp' of type Node*
Make temp point to ‘list1’
While (temp->next is NOT NULL):
Make ‘temp’ as ‘temp->next’
//bringing temp to the end of list1
Make temp->next point to ‘list2’
Function Display (Node *list):
Initialize 'temp' of type Node*
Make temp point to list
While (temp is NOT NULL)
Print temp->data
Make temp as temp->next
Function main: //driver function
Initialize list1 and list2 of type Node* with value NULL
Call Getdetails (&list1)
Call Getdetails (&list2)
Call Concat (list1, list2)
Call Display (list1)
Output:-
} typedef Node;
Node *head = NULL, *head2=NULL, *rear = NULL, *rear2=NULL;
Function Copylist():
Output:-
3. Always do insertion at last and delete at delete (FIFO)
Pseudo Code:-
Initialaize struct Node:
struct Node{
int data;
struct Node* next;
}typedef Node;
Node *head=NULL, *rear=NULL;
Function Dequeue():
If ‘head’ points to NULL:
Print “Underflow”
Return
Function Display():
If ‘head’ points to NULL:
Print “Underflow”
Return
Assign a ‘temp’ variable of type Node* point to ‘head’
While (‘temp’ is NOT NULL):
Print ‘temp->data’
Make ‘temp’ point to ‘temp->next’
/* Make a driver code asking from the user each time to choose the
function */
Output:
4. Always do insertion and deletion at first (LIFO)
Pseudo Code:
Initialaize struct Node:
struct Node{
int data;
struct Node* next;
}typedef Node;
Node *head=NULL;
Function Pop():
If ‘head’ points to NULL:
Print “Underflow”
Return
Function Peek():
If ‘head’ points to NULL:
Print “Underflow”
Return
Print ‘head->data’
Function Display():
If ‘head’ points to NULL:
Print “Underflow”
Return
Assign a ‘temp’ variable of type Node* point to ‘head’
While (‘temp’ is NOT NULL):
Print ‘temp->data’
Make ‘temp’ point to ‘temp->next’
/* Make a driver code asking from the user each time to choose the
function */
Output:
5. Make circular queue using SLL
Pseudo Code:
Initialaize struct Node:
struct Node{
int data;
struct Node* next;
}typedef Node;
Node *head=NULL, *rear=NULL;
Function Dequeue():
Function Display():
Function Discard():
While head is NOT NULL:
Call Dequeue()
/* Make a driver code asking from the user each time to choose the
function */
OUTPUT: