Singly Link List
Singly Link List
Variable :
FIRST : is NODE type pointer which stores address of first node
CH : which is used to get whether user want to continue or not.
[Link]
Function COUNT (FRONT)
This function is used to count total number of node in the list. Description
as per create function. This function return total number of node in list.
Variable :
COUNT : is used to store the total number of node.
[Link]
Function INSERT(FRONT,KEY,VAL)
This function inserts value before the given value. Description as per
create function. KEY is node before which we want to insert. VAL is variable
which store the information of value to be inserted. This function returns address
of first node.
Variable :
NEW : is a NODE type pointer which store information of new node to be
inserted.
TEMP : is NODE type pointer which stores address of first node.
[Link]
Function SEARCH (FRONT, KEY)
This function is used search any key value from the given list. Description
as per create function. KEY is value which is to be searched. This function return
true or false whether given value is in list or not.
Variable :
TRUE : it stores 1
FALSE : it stores 0.
Variable :
TRUE : it stores 1
FALSE : it stores 0
[Link]
Procedure APPEND(FRONT,VAL)
This procedure is used to append new node at last. Description as per
create function. VAL is used to store the value to be inserted at last.
Variable :
NEW : is a NODE type pointer which store information of new node to be
append.
[Link]
Function DELETE (FRONT,KEY)
This function is used to delete a node from the list. Description as per
create function. KEY is node which is to be deleted. This function returns address
of first node.
Variable :
FIRST : is NODE type pointer which stores address of first node
REMOVE : is NODE type pointer which stores the node to be deleted.
[Link]
Procedure SORT(FRONT)
This procedure is used to sort the list. Description as per create function.
Variable :
OUTER : is NODE type pointer variable used to iterating the outer loop.
INNER : is NODE type pointer variable used to iterating the inner loop.
TEMP : is NODE type pointer variable used for swapping the values of
two nodes.
[Link]
DOUBLY LINK LIST
Variable :
FIRST : is NODE type pointer which stores address of first node
CH : which is used to get whether user want to continue or not.
[Link]
Procedure PRINT (FRONT)
This procedure prints the information of all the nodes. Description as per
create function.
Procedure APPEND(FRONT,VAL)
This procedure is used to append new node at last. Description as per
create function. VAL is used to store the value to be inserted at last.
Variable :
NEW : is a NODE type pointer which store information of new node to be
append.
[Link]
Function DELETE (FRONT,KEY)
This function is used to delete a node from the list. Description as per
create function. KEY is node which is to be deleted. This function returns address
of first node.
Variable :
FIRST : is NODE type pointer which stores address of first node
REMOVE : is NODE type pointer which stores the node to be deleted.
[Link]
Function INSERT(FRONT,KEY,VAL)
This function inserts value before the given value. Description as per
create function. KEY is node before which we want to insert. VAL is variable
which store the information of value to be inserted. This function returns address
of first node.
Variable :
NEW : is a NODE type pointer which store information of new node to be
inserted.
TEMP : is NODE type pointer which stores address of first node.
[Link]
CIRCULAR LINK LIST
Variable :
FIRST : is NODE type pointer which stores address of first node
CH : which is used to get whether user want to continue or not.
[Link]
Procedure PRINT (FRONT)
This procedure prints the information of all the nodes. Description as per
create function.
Variable :
FIRST : Description as per create function.
[Link]
Function INSERT(FRONT,KEY,VAL)
This function inserts value before the given value. Description as per
create function. KEY is node before which we want to insert. VAL is variable
which store the information of value to be inserted. This function returns address
of first node.
Variable :
NEW : is a NODE type pointer which store information of new node to be
inserted.
TEMP : is NODE type pointer which stores address of first node.
[Link]
Function DELETE (FRONT,KEY)
This function is used to delete a node from the list. Description as per
create function. KEY is node which is to be deleted. This function returns address
of first node.
Variable :
FIRST : is NODE type pointer which stores address of first node
REMOVE : is NODE type pointer which stores the node to be deleted.
Stack
1) STACK USING ARRAY: -
If TOS >=SIZE-1
Then
Write („Stack Overflow……..‟)
Return
TOS TOS+1
S [TOS] VAL
Step 4: [Finished]
Return
--------------------------------------------------------------------------------------------------
2) Function POP ( )
[Description]
If TOS < 0
Then
Write („Stack Underflow…..‟)
Return -1
Step 2: [Decrement pointer]
VAL S [TOS]
TOS TOS – 1
Return VAL
---------------------------------------------------------------------------------------
[Link]
INDEX TOS – KEY +1
If INDEX < 0
Then
Write („Stack Underflow…..‟)
Return -1
Return S [INDEX]
--------------------------------------------------------------------------------------
If INDEX < 0
Then
Write („Stack Underflow…..‟)
Return -1
S [INDEX] VAL
Return 1
--------------------------------------------------------------------------------------
4) Procedure PRINT ( )
[Description]
[Link]
Step 2: [Print the value from stack]
Step 3: [Finished]
Return
NEWNODE NODE
Step 4: [Finished]
Return
--------------------------------------------------------------------------------------------------
3) Function POP ( )
[Description]
If TOS = NULL
Then
Write („Stack Underflow…..‟)
Return -1
[Link]
TOS NEXT [TOS]
Return VAL
---------------------------------------------------------------------------------------
5) Function PEEP ( KEY)
[Description]
TEMP TOS
I 1
Repeat While TEMP # NULL
If I = KEY
Then
Return 1
Else
TEMP (NEXT) TEMP
I I+1
Return -1
--------------------------------------------------------------------------------------
6) Function CHANGE ( KEY , VAL)
[Description]
TEMP TOS
I 1
Repeat While TEMP # NULL
If I = KEY
Then
INFO (TEMP) VAL
Return 1
Else
TEMP (NEXT) TEMP
I I+1
[Link]
Return -1
--------------------------------------------------------------------------------------
7) Procedure PRINT ( )
[Description]
TEMP TOS
Step 3: [Finished]
Return
[Link]
Queue
1) Procedure ( VAL )
[Description]
If FRONT = = -1
Then
FRONT 0
REAR REAR +1
Q [REAR] VAL
Step 5: [Finished]
Return
--------------------------------------------------------------------------------------------
2) Function DELETE ( )
[Description]
If FRONT < 0
Then
Write („Queue Underflow……‟)
[Link]
Return -1
VAL Q [FRONT]
If (FRONT = REAR)
Then
FRONT REAR -1
Else
FRONT FRONT +1
Return VAL
----------------------------------------------------------------------------------------------
3) Procedure PRINT
[Description]
If FRONT < 0
Then
Write („Underflow…..‟)
Return
Step 3: [Finished]
Return
NEWNODE NODE
[Link]
Step 2: [Check memory is available or not]
If NEWNODE = NULL
Then
Write („Queue Overflow……)
Return
If REAR = NULL
Then
FRONT REAR NEWNODE
NEXT (REAR) NULL
Return
If FRONT = NULL
Then
Write („Queue Underflow……‟)
Return -1
[Link]
Return VAL
----------------------------------------------------------------------------------------------
6) Procedure PRINT
[Description]
If TEMP = NULL
Then
Write („Underflow…..‟)
Return
TEMP FRONT
Step 4: [Finished]
Return
Circular Queue
4) CIRCULAR QUEUE :
7) Procedure ( VAL )
[Description]
[Link]
If REAR = 0 AND REAR=SIZE – 1
Then
Write („Overflow…..‟)
Return
If REAR = FRONT -1
Then
Write („Overflow…..‟)
Return
If REAR = SIZE – 1
Then
REAR = 0
Q [REAR] VAL
Else If REAR= -1
Then
REAR FRONT 0
Q [REAR] VAL
Else
REAR REAR +1
Q [REAR] VAL
Step 3: [Finished]
Return
--------------------------------------------------------------------------------------------
8) Function DELETE ( )
[Description]
If FRONT < 0
Then
Write („Queue Underflow……‟)
Return -1
VAL Q [FRONT]
If FRONT = REAR
[Link]
Then
FRONT REAR -1
Else If FRONT = SIZE – 1
Then
FRONT 0
Else
FRONT FRONT + 1
Return VAL
----------------------------------------------------------------------------------------------
9) Procedure PRINT
[Description]
If FRONT < 0
Then
Write („Underflow…..‟)
Return
Step 3: [Finished]
Return
Tree
Function CREATE(T,VAL)
[ROOT=Dummy header for the root of the binary tree initialized by NULL,
[Link]
NEWNODE=Variable points to the new element,
T=Temporary variables for traverse the tree,
INFO=Information part of node.]
Function INORDER(T)
[T = Temporary pointer variable initialized with root,
[Link]
INFO=Information part of node,
LEFT=Pointer to left most node,
RIGHT=Pointer to right most node,]
Step 1: [Repeat step 2,3,4 and check that T is not equal to NULL ]
If T!=NULL
Then
Function PREORDER(T)
[T = Temporary pointer variable initialized with root,
INFO=Information part of node,
LEFT=Pointer to left most node,
RIGHT=Pointer to right most node,]
Step 1: [Repeat step 2,3,4 and check that T is not equal to NULL ]
If T!=NULL
Then
[Link]
Function POSTORDER(T)
[T = Temporary pointer variable initialized with root,
INFO=Information part of node,
LEFT=Pointer to left most node,
RIGHT=Pointer to right most node,]
Step 1: [Repeat step 2,3,4 and check that T is not equal to NULL ]
If T!=NULL
Then
Step 1: [Repeat step 2,3,4 and check that T is not equal to NULL ]
If T!=NULL
Then
[Link]
6. Algorithm For Search of Binary Tree:-
Function SEARCH(T,KEY)
[T = Temporary pointer variable initialized with root,
INFO=Information part of node,
LEFT=Pointer to left most node,
RIGHT=Pointer to right most node.]
[Link]
Read (KEY)
Sorting
BUBBLE SORT
[Link]
The bubble sort loops through the elements in the list comparing the adjacent element and
moves the largest element to the top of the list
step 1: [ Initialize]
I 0
Step 3: [Initialize]
J 0
temp a[j]
a[j] a[j+1]
a[j+1] temp
endif
step 6: Exit
[Link]
SELECTION SORTING
Selection sorting starts from fist element and searches the entire list until finds the
minimum value. The sort places minimum value in the first place, select the second
element and searches for the second smallest element.
Step 1: [initialize]
I 0
Step 3: [initialize]
J I+1
temp a[j]
a[j] a[j]
a[j] temp
endif
step 6: j j+1
step 7: I I+1
step 8: Exit
[Link]
LINEAR SEARCH
Step 1: [initaialize]
I 0
Flag 1
Flag 0
( prompt the message search successful)
write “search is successful”
(increasing the value of variable I by 1)
I I+1
Step 5: Exit
[Link]
BINARY SEARCH
BINARY_SEARCH (KEY,N,A)
Binary search works for sorted list and is a very efficient [Link] is use to
find the location of a given element or record in a list.
Step 1: [initialize]
Low 0
upper n-1
Flag 1
mid (low+upper)/2
step 4: if (key = a[I]) then
upper mid-1
else if
(change upper to mid)
low mid+1
else if
(when key is found)
(key = a[mid])
[Link]
flag 0
return
step 6: Exit
[Link]
DOUBLE ORDER LINK LIST
DOUBLE_LIST (HEAD,VAL)
[This function to insert an element in the list which sorted to its info field and
value is the info field of the new node and prev is the field which point to previous node]
new=node
info(new)=val
if (temphead=NULL) then
temphead newnode
next(temphead) NULL
return (temphead)
step 4: [does the newnode precede all other node in the list?]
prev(newnode) prev(temphead)
next(newnode) temphead
temphead newnode
return (temphead)
else
first temphead
endwhile
next(newnode) next(temphead)
prev(newnode) temphead
next(temphead) newnode
return (first)
step 5: exits
[Link]
[Link]
[Link]