The document outlines the concept of a stack, which operates on a Last In First Out (LIFO) principle. It details the basic operations of a stack, including push and pop, along with supporting functions such as peek, isFull, and isEmpty, each with their respective algorithms. The push operation adds data to the stack, while the pop operation removes and returns the top data element.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
21 views10 pages
Stacks
The document outlines the concept of a stack, which operates on a Last In First Out (LIFO) principle. It details the basic operations of a stack, including push and pop, along with supporting functions such as peek, isFull, and isEmpty, each with their respective algorithms. The push operation adds data to the stack, while the pop operation removes and returns the top data element.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10
Stack
Stack
• LIFO(Last In First Out)
• Basic Operations on Stack
– Push() – Pop() Push Operation Algorithm for Push Operation begin procedure push: stack, data if stack is full return null endif top ← top + 1 stack[top] ← data end procedure Pop Operation Algorithm for Pop Operation begin procedure pop: stack, data if stack is empty return null endif data ← stack[top] top ← top - 1 return data end procedure Supporting Stack Functions
• peek() − get the top data element of the
stack, without removing it.
• isFull() − check if stack is full.
• isEmpty() − check if stack is empty.
Algorithm of peek() function
begin procedure peek
return stack[top] end procedure Algorithm of isfull() function
begin procedure isfull
if top equals to MAXSIZE return true else return false endif end procedure Algorithm of isempty() function begin procedure isempty if top = -1 return true else return false endif end procedure