Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.

Slides:



Advertisements
Similar presentations
Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample.
Advertisements

Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Stacks Chapter 11.
Arithmetic Expressions Infix form –operand operator operand 2+3 or a+b –Need precedence rules –May use parentheses 4*(3+5) or a*(b+c)
Stacks CS 3358 – Data Structures. What is a stack? It is an ordered group of homogeneous items of elements. Elements are added to and removed from the.
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.
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 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.
Introduction to Stacks What is a Stack Stack implementation using arrays. Application of Stack.
Main Index Contents 11 Main Index Contents Tree StructuresTree Structures (3 slides) Tree Structures Tree Node Level and Path Len. Tree Node Level and.
Stacks & Queues Infix Calculator CSC 172 SPRING 2002 LECTURE 5.
Introduction to Stacks What are Stacks? Stack implementation using arrays. Stack application.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
Introduction to Stacks What is a Stack Stack implementation using array. Stack implementation using linked list. Applications of Stack.
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 removed.
1 Introduction to Stacks What is a Stack? Stack implementation using array. Stack implementation using linked list. Applications of Stacks.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 7 Ming Li Department of.
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.
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.
Class 4: Stacks. cis 335 Fall 2001 Barry Cohen What is a stack? n A stack is an ordered sequence of items, of which only the last (‘top’) item can be.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 8 Ming Li Department of.
Data Structures Using C++ 2E Chapter 7 Stacks. Data Structures Using C++ 2E2 Objectives Learn about stacks Examine various stack operations Learn how.
Ceng-112 Data Structures ITurgut Kalfaoglu 1 Chapter 3 Stacks.
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
Data Structures: CSCI 362 – Stack Implementation Data Structures: CSCI 362 – Stack Implementation lecture notes adapted from Data Structures with C++ using.
Stack Applications.
1 Stacks Chapter 4 2 Introduction Consider a program to model a switching yard –Has main line and siding –Cars may be shunted, removed at any time.
Main Index Contents 11 Main Index Contents Week 4 – Stacks.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
1 Stacks Stack Examples Stack API More Examples/Uses Base Conversion Activation Records RPN Implementing a Stack Stacks.
Stacks 1. Stack  What is a stack? An ordered list where insertions and deletions occur at one end called the top. Also known as last-in-first-out (LIFO)
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 2)
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.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
Main Index Contents 11 Main Index Contents Sets Defined by a key along with other data Sets Defined by a key along with other data Key-Value Data Key-Value.
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.
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.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 2a. Simple Containers: The Stack.
CSC 172 DATA STRUCTURES. A TALE OF TWO STRUCTURES.
Data Structures Using C++ 2E
Stacks Chapter 5.
Recap: Solution of Last Lecture Activity
Stacks Chapter 7 introduces the stack data type.
CSC 172 DATA STRUCTURES.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Stacks Chapter 4.
Algorithms and Data Structures
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
COMPUTER 2430 Object Oriented Programming and Data Structures I
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Stacks Chapter 5 Adapted from Pearson Education, Inc.
Stacks, Queues, and Deques
Lecture 5 Stacks King Fahd University of Petroleum & Minerals
COMPUTER 2430 Object Oriented Programming and Data Structures I
Queue Applications Lecture 31 Mon, Apr 9, 2007.
Introduction to Stacks
Stack.
Queue Applications Lecture 31 Tue, Apr 11, 2006.
Introduction to Stacks
Stacks.
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
The List Container and Iterators
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.
© 2016 Pearson Education, Ltd. All rights reserved.
CHAPTER 3: Collections—Stacks
Presentation transcript:

Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass Stack (3 slides) Class Stack Using a Stack to Create a Hex # Using a Stack to Create a Hex # Uncoupling Stack Elt’sUncoupling Stack Elt’s (6 slides) Uncoupling Stack Elt’s Activation Records Activation Records RPN Chapter 7 – Stacks Infix Notation Infix Notation Summary SlidesSummary Slides (4 slides) Summary Slides

Main Index Contents 2 Stacks A stack is a sequence of items that are accessible at only one end of the sequence.

Main Index Contents 33 Main Index Contents Further Stack Examples

Main Index Contents 4 Pushing/Popping a Stack Because a pop removes the item last added to the stack, we say that a stack has LIFO (last- in/first-out) ordering.

Main Index Contents 55 Main Index Contents CLASS stack Constructor stack(); Create an empty stack CLASS stack Operations bool empty(); const Check whether the stack is empty. Return true if it is empty and false otherwise.

Main Index Contents 66 Main Index Contents CLASS stack Operations void pop(); Remove the item from the top of the stack. Precondition:The stack is not empty. Postcondition:Either the stack is empty or the stack has a new topmost item from a previous push. void push(const T& item); Insert the argument item at the top of the stack. Postcondition: The stack has a new item at the top.

Main Index Contents 77 Main Index Contents CLASS stack Operations int size() const; Return the number of items on the stack. T& top() const; Return a reference to the value of the item at the top of the stack. Precondition:The stack is not empty. const T& top() const; Constant version of top().

Main Index Contents 88 Main Index Contents Using a Stack to Create a Hex Number

Main Index Contents 99 Main Index Contents Uncoupling Stack Elements

Main Index Contents 10 Main Index Contents Uncoupling Stack Elements

Main Index Contents 11 Main Index Contents Uncoupling Stack Elements

Main Index Contents 12 Main Index Contents Uncoupling Stack Elements

Main Index Contents 13 Main Index Contents Uncoupling Stack Elements

Main Index Contents 14 Main Index Contents Uncoupling Stack Elements

Main Index Contents 15 Main Index Contents

Main Index Contents 16 Main Index Contents

Main Index Contents 17 Main Index Contents Infix Expression Rules The figure below gives input precedence, stack precedence, and rank used for the operators +, -, *, /, %, and ^, along with the parentheses. Except for the exponential operator ^, the other binary operators are left-associative and have equal input and stack precedence. Precedence SymbolInput precedence Stack precedence Rank * / %2 2 ^4 3 (5 0 )0 0 0

Main Index Contents 18 Main Index Contents Summary Slide 1 §- Stack -Storage Structure with insert (push) and erase (pop) operations occur at one end, called the top of the stack. -The last element in is the first element out of the stack, so a stack is a LIFO structure.

Main Index Contents 19 Main Index Contents Summary Slide 2 §- Recursion -The system maintains a stack of activation records that specify: 1)the function arguments 2)the local variables/objects 3)the return address -The system pushes an activation record when calling a function and pops it when returning.

Main Index Contents 20 Main Index Contents Summary Slide 3 §- Postfix/RPN Expression Notation -places the operator after its operands -easy to evaluate using a single stack to hold operands. -The rules: 1) Immediately push an operand onto the stack. 2) For a binary operator, pop the stack twice, perform the operation, and push the result onto the stack. 3) At the end a single value remains on the stack. This is the value of the expression.

Main Index Contents 21 Main Index Contents Summary Slide 4 §- Infix notation -A binary operator appears between its operands. -More complex than postfix, because it requires the use of operator precedence and parentheses. -In addition, some operators are left-associative, and a few are right-associative.