1) STACK USING ARRAY: -
1) Procedure PUSH (VAL)
[Description]
Step 1: [Check stack is empty or not]
If TOS >=SIZE-1
Then
Write (‘Stack Overflow……..’)
Return
Step 2: [Increment TOS by 1]
TOS ¬ TOS+1
Step 3: [Assign value]
S [TOS] ¬ VAL
Step 4: [Finished]
Return
--------------------------------------------------------------------------------------------------
2) Function POP ( )
[Description]
Step 1: [Check stack is empty or not]
If TOS < 0
Then
Write (‘Stack Underflow…..’)
Return -1
Step 2: [Decrement pointer]
VAL ¬ S [TOS]
TOS ¬ TOS – 1
Step 3: [Return deleted value]
Return VAL
---------------------------------------------------------------------------------------
2) Function PEEP ( KEY)
[Description]
Step 1: [Find the element number]
INDEX ¬ TOS – KEY +1
Step 2: [Check stack is empty or not]
If INDEX < 0
Then
Write (‘Stack Underflow…..’)
Return -1
Step 3: [Return the element from stack]
Return S [INDEX]
--------------------------------------------------------------------------------------
3) Function CHANGE ( KEY , VAL)
[Description]
Step 1: [Find the element number]
INDEX ¬ TOS – KEY +1
Step 2: [Check stack is empty or not]
If INDEX < 0
Then
Write (‘Stack Underflow…..’)
Return -1
Step 3: [Change the value from stack]
S [INDEX] ¬VAL
Return 1
--------------------------------------------------------------------------------------
4) Procedure PRINT ( )
[Description]
Step 1: [Check Stack is empty or not]
If TOS < 0
Then
Write (‘Stack Underflow……’)
Return
Step 2: [Print the value from stack]
Repeat For I = TOS, TOS-1…….While I >= 0
Write S [I]
Step 3: [Finished]
Return
1) STACK USING LINK LIST: -
1) Procedure PUSH (VAL)
[Description]
Step 1: [Allocate the memory]
NEWNODE Ü NODE
Step 2: [Read the INFO]
Read (INFO (NEWNODE))
Step 3: [Arrange the address]
NEXT (NEWNODE) ¬ TOS
TOS ¬ NEWNODE
Step 4: [Finished]
Return
--------------------------------------------------------------------------------------------------
3) Function POP ( )
[Description]
Step 1: [Check stack is empty or not]
If TOS = NULL
Then
Write (‘Stack Underflow…..’)
Return -1
Step 2: [Assign deleted value in VAL]
VAL ¬ INFO (TOS)
Step 3: [Assign the address of next NODE in TOS]
TOS ¬ NEXT [TOS]
Return VAL
---------------------------------------------------------------------------------------
5) Function PEEP ( KEY)
[Description]
Step 1: [Store TOS into TEMP]
TEMP ¬ TOS
Step 2: [Repeat the loop up to last NODE]
I ¬ 1
Repeat While TEMP # NULL
If I = KEY
Then
Return 1
Else
TEMP ¬ (NEXT) TEMP
I ¬ I+1
Step 3: [KEY not found, so return false]
Return -1
--------------------------------------------------------------------------------------
6) Function CHANGE ( KEY , VAL)
[Description]
Step 1: [Store TOS into TEMP]
TEMP ¬ TOS
Step 2: [Repeat the loop up to last NODE]
I ¬ 1
Repeat While TEMP # NULL
If I = KEY
Then
INFO (TEMP) ¬ VAL
Return 1
Else
TEMP ¬ (NEXT) TEMP
I ¬ I+1
Step 3: [KEY not found, so return false]
Return -1
--------------------------------------------------------------------------------------
7) Procedure PRINT ( )
[Description]
Step 1: [Store TOS into TEMP]
TEMP ¬ TOS
Step 2: [Repeat the loop till the last NODE]
Repeat While TEMP # NULL
Write INFO (TEMP)
TEMP ¬ NEXE (TEMP)
Step 3: [Finished]
Return
0 comments:
Post a Comment