Professional Documents
Culture Documents
com
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.
Variable :
COUNT : is used to store the total number of node.
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.
Variable :
TRUE : it stores 1
FALSE : it stores 0.
Variable :
TRUE : it stores 1
FALSE : it stores 0
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.
Variable :
FIRST : is NODE type pointer which stores address of first node
REMOVE : is NODE type pointer which stores the node to be deleted.
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.
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.
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.
Variable :
FIRST : is NODE type pointer which stores address of first node
REMOVE : is NODE type pointer which stores the node to be deleted.
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.
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.
Variable :
FIRST : Description as per create function.
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.
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
---------------------------------------------------------------------------------------
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]
Step 3: [Finished]
Return
NEWNODE NODE
Step 4: [Finished]
Return
--------------------------------------------------------------------------------------------------
3) Function POP ( )
[Description]
If TOS = NULL
Then
Write („Stack Underflow…..‟)
Return -1
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
TEMP TOS
Step 3: [Finished]
Return
www.gtuking.blogspot.com
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……‟)
www.gtuking.blogspot.com
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
www.gtuking.blogspot.com
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
If TEMP = NULL
Then
Write („Underflow…..‟)
Return
TEMP FRONT
Step 4: [Finished]
Return
Circular Queue
4) CIRCULAR QUEUE :
7) Procedure ( VAL )
[Description]
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
www.gtuking.blogspot.com
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,
www.gtuking.blogspot.com
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,
www.gtuking.blogspot.com
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
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
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.]
Sorting
BUBBLE SORT
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
www.gtuking.blogspot.com
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
www.gtuking.blogspot.com
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
www.gtuking.blogspot.com
BINARY SEARCH
BINARY_SEARCH (KEY,N,A)
Binary search works for sorted list and is a very efficient technique.It 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])
flag 0
return
step 6: Exit
www.gtuking.blogspot.com
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
www.gtuking.blogspot.com
www.gtuking.blogspot.com