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
IN DATA STRUCTURES Introduction
Friedrich L. Bauer, inventor of the stack.
1. A stack is an abstract data type that serves as a collection of elements, with two main operations: 2. Push, which adds an element to the collection, and Pop, which removes the most recently added element. 3. Push and pop operations occur only at one end I.e., top end. 4. The order in which an element added to or removed from a stack is described as last in first Out(LIFO) . Operations performed on stack
Push : Adds an element to the top of the stack.
Pop : Removes the topmost element from the stack. isempty : Checks whether the stack is empty. isfull: Checks whether the stack is full. 1. Top : Displays the topmost element of the stack. Stack Representation Condition
1. Underflow Condition: When a stack is empty (i.e. TOP=
-1) and we try to delete more element from it. 2. Underflow happens when we try to pop an item from an empty stack. 3. Overflow happens when we try to push more items on a stack than it can hold. Uses :
1. A Stack can be used for evaluating expressions
consisting of operands and operators. 2. Stacks can be used for Backtracking, i.e., to check parenthesis matching in an expression. 3. It can also be used to convert one form of expression to another form. 4. It can be used for systematic Memory Management. Advantages:
A Stack helps to manage the data in the ‘Last in First out’
method. When the variable is not used outside the function in any program, the Stack can be used. It allows you to control and handle memory allocation and deallocation. 1. It helps to automatically clean up the objects. 2. Stack is easy to learn and implement for beginners. 3. Stacks are used to solving problems that work on recursion. Disadvantages:
It is difficult in Stack to create many objects as it
increases the risk of the Stack overflow. It has very limited memory. 1. In Stack, random access is not possible Example:
1. A real-life example is a stack of plates: you can only
take a plate from the top of the stack, and you can only add a plate to the top of the stack. Applications:
Expression conversion such as infix to postfix,
infix to prefix. Expression evaluation. Parsing well-formed parenthesis. Decimal to binary conversion. Reversing a string. 1. Storing function calls. THANK YOU t YOU