+ All Categories
Home > Engineering > Data structure Stack

Data structure Stack

Date post: 17-Jul-2015
Category:
Upload: praveen-vishwakarma
View: 76 times
Download: 3 times
Share this document with a friend
Popular Tags:
18
DATA STRUCTURE : ‘STACKS’. PPO Presentation.
Transcript
Page 1: Data structure Stack

DATA STRUCTURE : ‘STACKS’.

PPO Presentation.

Page 2: Data structure Stack

To Understand and apply the knowledge of the Data Structure ‘Stack’ in the

Application Programs .

Objectives:

Page 3: Data structure Stack

A stack is a linear data structure in which addition or deletion

of element take place at one end only.

Stack is a special type of data structure where insertion is done

from one end called 'top' of stack and deletion will be done

from the same end. Here, the last element inserted will be on

the top of the stack. Since deletion is done from the same end,

last element inserted is the first element to be deleted.

So, stack is also called Last In First Out(LIFO)data structure.

Introduction To Stack.

Page 4: Data structure Stack

A stack is an ordered collection of items where

the addition of new items and the removal of

existing items always takes place at the same

end. This end is commonly referred to as the

"TOP". The end opposite the top is known as the

"BASE".

Definition of Stack :

Page 5: Data structure Stack

A stack is a data structure that is used to store elements but all the elements can be inserted or deleted from the TOP of the stack.

The top of the stack is the top most part of the stack, something like a rectangular box which has only opening at the top.

Basic Concept of Stack

Page 6: Data structure Stack

The shown figure is a simple representation of a stack. As we can notice that the TOP of the stack is the only means by which we can insert or delete elements to the stack.

Simple representation of a Stack.

* All the elements in the stack follow the simple rule of Last In First Out (LIFO). This means that the elements inserted in the last are the elements to be deleted first.

Page 7: Data structure Stack

1. Max size: This term is used to refer the maximum size of the stack. This is not a standard term.

2. Stack empty or underflow : If stack has no elements and pop operation is performed or an element is deleted from empty stack then such condition is called as "Underflow".

3. Overflow or stack full: If stack is full i.e. there is no more space for new item and push operation is done then such condition is called as '‘Overflow.''

Terminology:

Page 8: Data structure Stack

createstack( ) :To initializes as an empty stack.

Insertion / (PUSH) :The process of adding new elements to the top of stack is called push operation. Pushing of an element is nothing but adding element to the stack.

(iii) Deletion / (POP) :The process of deleting an element from top of a stack is called POP.

Primitive operations on stacks

Page 9: Data structure Stack

TOP : A pointer, which keeps track of the top element in the Stack. If an array of size N is declared to be a stack, then TOP will be -1 when the stack is empty and is N when the stack is full.

isEmpty( ) : This Function is used to check whether a stack is empty or not. This function returns Boolean value TRUE if stack is empty .

isFull( ) : This Function is used to check weather a stack becomes full or not. It returns Boolean TRUE if stack is full else FALSE.

Page 10: Data structure Stack

Understanding Push and Pop Operation .

Page 11: Data structure Stack

Infix expressions An operator appears between its operands

Example: a + b

Prefix expressions An operator appears before its operands

Example: + a b

Postfix expressions An operator appears after its operands

Example: a b +

Types of Notations:

Page 12: Data structure Stack

To convert a fully parenthesized infix expression to a prefix form

Move each operator to the position marked by its corresponding open parenthesis

Remove the parentheses

Example

Infix expression: ( ( a + b ) * c )

Prefix expression: * + a b c

Converting an Infix to Prefix Expression.

Page 13: Data structure Stack

To convert a fully parenthesized infix expression to a postfix form

Move each operator to the position marked by its corresponding closing parenthesis

Remove the parentheses

Example

Infix form: ( ( a + b ) * c )

Postfix form: a b + c *

Converting an Infix to Postfix Expression.

Page 14: Data structure Stack

PROGRAMING

Page 15: Data structure Stack

Program for static Implementation of Stack using Array.

void push()

{

if(top==MAX)

printf("\n\n*** STACK OVERFLOW ***\n\n");

else

{

printf("\n\n Enter the item to be pushed into the stack:\n\n");

scanf("%d",&item);

top++;

stack[top]=item;

}

}

Page 16: Data structure Stack

void pop(){if(top==-1)printf("\n\n\n*** STACK IS EMPTY !!! ***\n\n");else{item=stack[top];top--;printf("\n\n\n The deleted item from stack is %d\n\n",item);}}

Page 17: Data structure Stack

Summary • A stack is a container of objects that are inserted and removed

according to the Last-In-First-Out (LIFO) principle .

• A stack is a list of elements in which an element may be inserted or deleted at one end which is known as TOP of the stack .

• PUSH operation adds an item to the top of the stack while POP removes the item from the top .

• The process of writing the operators of an expression either before their operands or after them is called Polish notation .

Page 18: Data structure Stack

Thank you !!!


Recommended