0% found this document useful (0 votes)
2 views3 pages

Stack Data Structure Operations Explained

algorithms related to the stack concept

Uploaded by

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

Stack Data Structure Operations Explained

algorithms related to the stack concept

Uploaded by

Pace Infotech
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Stack :

The statck is a LIFO (Last In First Out) data [Link] the case of stack ,
there are three basic operations,

(i) push operation

To add an element on the stack

(a) Initially stack is empty (b) 5 (c) 10

4 4
4

3 3 TOP 3

TOP=0 TOP
2 2 10
10 2
1
(ii) pop operation

To remove
1 a element present at the top of the
5 stack. 1 5
1
(a) Currently (b) 10

4 4

3 3
TOP

10 TOP
10 10
2
1
(iii) peep operation 4
1 2

It will just return the top most value from the stack and doesn’t
remove it from the stack. 5 3 5
1 1
(a) 10
10
10 2
1

5
1
TOP

(A) Procedure to Push operation


Procedure PUSH(STACK,MAX,TOP,VAL)
[Procedure to add an element to the stack , initially TOP is zero]

Step 1: If TOP=MAX then:


Write “STACK Overflow”.
Else:
(a) Set TOP:=TOP+1.
(b) Set STACK(TOP):=VAL
[End of If Structure]
Step 2: Return.

(B) Procedure to POP an element from the stack

Procedure POP(STACK,TOP)
[Procedure to delete an element from the stack]

Step 1: If TOP=0 then:


Write “Stack Underflow”.
Else:
(c) Set VAL:=STACK(TOP).
(d) Set TOP:=TOP-1.
(e) Return VAL.
[End of If Structure]
Step 2: Return.

(C) Procedure to PEEP an element from the stack

Procedure PEEP(STACK,TOP)
[Procedure to access top element from the stack]

Step 1: If TOP=0 then:


Write “Stack Underflow”.
Else:
(a) Set VAL:=STACK(TOP).
(b) Return VAL.
[End of If Structure]
Step 2: Return.

You might also like