Presentation is loading. Please wait.

Presentation is loading. Please wait.

STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai.

Similar presentations


Presentation on theme: "STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai."— Presentation transcript:

1 STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai

2 STACK Using Linked List What is Stack ?
Operation on Stack … ( PUSH and POP) Applications of Stack

3 STACK A stack is a LIFO structure and physically it can be implemented as an array or as a linked list. A stack is implemented as an array that inherits all the properties of an array and if implemented as a linked list , all characteristics of a linked list are possessed by it. top S T A C K

4 OPERATIONS ON STACK A stack is generally implemented with two basic operations- Push and Pop. Whatever way a stack may be implemented, insertion (push) and deletions (POP) occur at the top only. Push – Allows adding an element at the top of the Stack. Pop - Allows to remove an element from the top of the Stack.

5 Stack Operations (PUSH , POP) Example
top 6

6 Stack Operations (PUSH , POP) Example
top 1 6

7 Stack Operations (PUSH , POP) Example
7 top 1 6

8 Stack Operations (PUSH , POP) Example
8 7 top 1 6

9 Stack Operations (PUSH , POP) Example
8 7 top 1 6

10 Stack Operations (PUSH , POP) Example
7 top 1 6

11 CREATING A STACK (LINKED STACK)
The creation of a stack ( as a linked list) is the same as the creation of a linked list i.e., after getting a new node, TOP point to the newly inserted node.

12 Creating a Node for Stack
struct stack { int info; stack *next; } *top, s; Info next S

13 INSERTION IN A LINKED STACK (PUSH)
TOP Fig A 44 55 n TOP 33 44 55 n Fig B TOP 22 33 44 55 n Fig C As a push can only occur at the TOP gets modified every time. For instance, if we have a stack as shown in fig (a) after pushing 33 , it becomes as Fig (b). After pushing another element 22, it becomes as Fig (c).

14 DELETION (POP) FROM A LINKED STACK
TOP 22 33 44 55 n Fig A TOP 33 44 55 n Fig B TOP 44 55 n Fig C Deletion i.e. popping also require modification of TOP i.e. TOP is made to point to the next node in the sequence. For instance, if the stack is shown in Fig a; after popping 22 , it becomes as Fig b. After Popping 33 , it becomes a Fig c.

15 Application of Stack Reversing a Line POLISH NOTATION
CONVERSION OF INFIX EXPRESSION TO POSTFIX (SUFFIX) EXPRESSION

16 THANK YOU


Download ppt "STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai."

Similar presentations


Ads by Google