Call Stacks John Keyser. Stacks A very basic data structure. – Data structure: a container for holding data in a program. – Classes, structs can be thought.

Slides:



Advertisements
Similar presentations
The Stack Data Structure. Classic structure What is a Stack? An abstract data type in which accesses are made at only one end Last In First Out (LIFO)
Advertisements

Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Win32 Programming Lesson 4: Classes and Structures.
Data Structures - Stacks. What are data structures? Different ways to organize data What data structures have we used before? lists / arrays Deck (AceyDeucey)
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Infix to postfix conversion Process the tokens from a vector infixVect of tokens (strings) of an infix expression one by one When the token is an operand.
Fall 2008ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
CS 3013 & CS 502 Summer 2006 Digressions:– Producer-Consumer and Stacks 1 Two Digressions Stacks Producer-Consumer models.
Stacks Using Linked Lists Here, we use the same concept of the stack but eliminate the MAXIMUM data items constraint. Since we shall be using Linked Lists.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
1 Executing Method Calls This lecture tells you precisely how method calls are executed (a few details will have to wait until we get to classes and objects).
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Stacks (Revised and expanded from CIT 591). What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on.
Digression: the “Stack” 1 CS502 Spring 2006 Digression: the “Stack” Imagine the following program:– int factorial(int n){ if (n
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
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.
Preorder Traversal with a Stack Push the root onto the stack. While the stack is not empty n pop the stack and visit it.
) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression.
Data Structures: CSCI 362 – Stack Implementation Data Structures: CSCI 362 – Stack Implementation lecture notes adapted from Data Structures with C++ using.
Stacks CISC181 Spring 2004 P. T. Conrad University of Delaware.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
Stacks. An alternative storage structure for collections of entities is a stack. A stack is a simplified form of a linked list in which all insertions.
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.
 STACK STACK  BASIC STACK OPERATIONS BASIC STACK OPERATIONS  PUSH ALGORITHM PUSH ALGORITHM  POP ALGORITHM POP ALGORITHM  EVALUATING A POSTFIX EXPRESSION.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
The Stack This is a special data structure: –The first item to be placed into the stack will be the last item taken out. Two basic operations: –Push: Places.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Activation records and function invocation.
1 The Stack Class Final Review Fall 2005 CS 101 Aaron Bloomfield.
EASTERN MEDITERRANEAN UNIVERSITY Stacks EENG212 –Algorithms and Data Structures.
Basic Data Structures Stacks. A collection of objects Objects can be inserted into or removed from the collection at one end (top) First-in-last-out.
Chapter 4 Stacks and Queues © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Copyright © Curt Hill Stacks An Useful Abstract Data Type.
CSC 205 – Java Programming II Lecture 30 April 3, 2002.
Stack Data Structure By Marwa M. A. Elfattah. Stack - What A stack is one of the most important non- primitive linear data structure in computer science.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
STACK Data Structure
Stacks. What is a Stack? A stack is a type of data structure (a way of organizing and sorting data so that it can be used efficiently). To be specific,
Chapter 6.6, 11, 16 Stacks 1CSCI 3333 Data Structures.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Lecture 16 Stacks and Queues Richard Gesick. Sample test questions 1.Write a definition for a Node class that holds a number. 2.Write a method that sums.
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Chapter 10 And, Finally... The Stack
Outline for this evening
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
Dynamic Memory CSCE 121 J. Michael Moore.
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.
Chapter 10 The Stack.
Arithmetic using a stack
Pointers and Linked Lists
Stack Memory 1 (also called Call Stack)
CSC 205 – Java Programming II
STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai.
Lecture 21 Stacks and Queues Richard Gesick.
Data structures.
Program to find equivalence classes
Stacks CS-240 Dick Steflik.
template< class T > class Stack { public:
Stacks LIFO C C B B B B A A A A A Push (A) Push (B) Push (C) Pop Pop.
Dynamic Memory CSCE 121.
Stacks.
Corresponds with Chapter 5
Implementing Functions: Overview
Presentation transcript:

Call Stacks John Keyser

Stacks A very basic data structure. – Data structure: a container for holding data in a program. – Classes, structs can be thought of as data structures – The vector is a data structure we have already used. Like forming a stack of objects Two basic operations – Push (add something to top of stack) – Pop (remove whatever is on top of stack

Example: Push 5 Push 10 Pop Push 8 Push 1 Pop 5 5

Example: Push 5 Push 10 Pop Push 8 Push 1 Pop 5 10

Example: Push 5 Push 10 Pop Push 8 Push 1 Pop 5 10

Example: Push 5 Push 10 Pop Push 8 Push 1 Pop 5 8 8

Example: Push 5 Push 10 Pop Push 8 Push 1 Pop

Example: Push 5 Push 10 Pop Push 8 Push 1 Pop

Example: Push 5 Push 10 Pop Push 8 Push 1 Pop 5 8

Example: Push 5 Push 10 Pop Push 8 Push 1 Pop 5

Functions (aka routines, methods, etc.) When a function is called, it is pushed onto a call stack. – What is pushed on is a “function activation record” – This record contains the information/variables the function uses (effectively the local scope When a function finishes, it is popped off of the call stack. – It might return a value to the prior item in the stack. The call stack can get very deep – many functions are called from one another 11Stroustrup/Programming -- Oct'10

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …}

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A B

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A B D

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A B

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A B E

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A B E G

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A B E

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A B

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A C

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A C D

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A C

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A C F

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A C

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack A

Example 7 different functions (A through F) int A() {… B(); C(); …} int B() {… D(); E(); …} int C() {… D(); F(); …} int D() {…} int E() {… G(); …} int F() {…} int G() {…} main() {… A(); …} Call Stack