MEMORY REPRESENTATION OF STACKS

Slides:



Advertisements
Similar presentations
INFIX, PREFIX, & POSTFIX EXPRESSIONS. Infix Notation We usually write algebraic expressions like this: a + b This is called infix notation, because the.
Advertisements

Stack & Queues COP 3502.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Stacks - 3 Nour El-Kadri CSI Evaluating arithmetic expressions Stack-based algorithms are used for syntactical analysis (parsing). For example.
Joseph Lindo Abstract Data Types Sir Joseph Lindo University of the Cordilleras.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title : Overview of Stack.
Stacks Chapter 5. Chapter Objectives  To learn about the stack data type and how to use its four methods: push, pop, peek, and empty  To understand.
Chapter 3 Stacks.
Stacks Chapter 5. Chapter 5: Stacks2 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop, peek, and empty.
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
Stacks CS-240 & CS-341 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed.
More About Stacks: Stack Applications Dan Nguyen CS 146, Spring 2004 Professor Sin-Min Lee.
Stack  A stack is a linear data structure or abstract data type for collection of items, with the restriction that items can be added one at a time and.
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
DATA STRUCTURE & ALGORITHMS CHAPTER 3: STACKS. 2 Objectives In this chapter, you will: Learn about stacks Examine various stack operations Discover stack.
COMP 121 Week 13: Stacks. Objectives Learn about the stack data type and how to use its four methods: push, pop, peek, and empty Understand how Java implements.
Due: 2007/11/12. Problem 1 Rewrite function Push and Pop (Program 3.10 and 3.12) using an additional variable lastOp as discussed on Page 146. The queue.
CHAPTER 3 STACK CSEB324 DATA STRUCTURES & ALGORITHM.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
Stacks An Abstract Data Type. Restricted Access Unlike arrays, stacks only allow the top most item to be accessed at any time The interface of a stack.
CHP-3 STACKS.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
1 Data Structures and Algorithms Stack. 2 The Stack ADT Introduction to the Stack data structure Designing a Stack class using dynamic arrays Linked Stacks.
Applications of Stack Maitrayee Mukerji. Stacks Last In First Out (LIFO List) ◦ FILO? Insertions and Deletions from the same end called the Top Push(),
1 Data Structures and Algorithms Stack. 2 The Stack ADT Introduction to the Stack data structure Designing a Stack class using dynamic arrays Linked Stacks.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
 Chapter 7 introduces the stack data type.  Several example applications of stacks are given in that chapter.  This presentation shows another use called.
Review Use of Stack Introduction Stack in our life Stack Operations
STACKS & QUEUES for CLASS XII ( C++).
Data Structures Using C++ 2E
Data Structure By Amee Trivedi.
Stacks Chapter 5.
Introduction Of Stack.
COMPSCI 107 Computer Science Fundamentals
Infix to postfix conversion
CE 221 Data Structures and Algorithms
CS 201 Data Structures and Algorithms
Lecture No.06 Data Structures Dr. Sohail Aslam
Program to search an element of array using linear search.
Objectives In this lesson, you will learn to: Define stacks
Stacks.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
STACKS.
Stacks Chapter 4.
Algorithms and Data Structures
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
PART II STACK APPLICATIONS
Stacks A stack is a data structure that is similar in spirit to a pile of cafeteria trays. Think about the trays in the dining halls: when the dining staff.
STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai.
Stacks, Queues, and Deques
Stack ADT Operations Application: Expression Evaluation
More About Stacks: Stack Applications
Stacks and Queues 1.
Cs212: Data Structures Computer Science Department Lecture 6: Stacks.
Stacks Data structure Elements added, removed from one end only
Stacks.
Stack.
More About Stacks: Stack Applications
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
LINEAR DATA STRUCTURES
DATA STRUCTURES IN PYTHON
Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as.
Presentation transcript:

MEMORY REPRESENTATION OF STACKS A stack can be represented in memory either as an array or as a singly linked list. In both the cases, insertion and deletion of elements is allowed at one end only. Insertion and deletion in the middle of the array or the linked list is not allowed. An array representation of a stack is static but linked list representation is dynamic in nature. Though array representation is a simple technique. it provides less flexibility and is not very efficient with respect to memory utilization because of wastage of memory space. Conversely, if the number of elements to be handled by the stack is more than the size of the stack, then it will not be possible to increase the size of stack to store these elements. .

To insert an element 1 in the STACK, Top is incremented by one and the element 1 is stored at STACK [Top]. Similarly, other elements can be added to the STACK until Top reaches 2 (see Figure 3.3). To pop an element from the STACK (data element 3), Top is decremented by one, which removes the element 3 from the STACK. Similarly, other ele­ments can be removed from the STACK until Top reaches -1. Figure 3.3 shows different states of STACK after performing push and pop operations on it.

struct stack { int item[MAX]; int Top; }; To implement stack as an array in C language, the following structure named stack needs to be defined. struct stack { int item[MAX]; int Top; };

APPLICATIONS OF STACKS reversing strings check­ing whether the arithmetic expression is properly parenthesized converting infix notation to postfix and prefix notations evaluating postfix expressions implementing recursion and function calls