Stacks Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.

Slides:



Advertisements
Similar presentations
CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
Advertisements

Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Stacks Chapter 21 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
COMPSCI 105 S Principles of Computer Science 13 Stacks.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Queues and Priority Queues
Chapter 13 Queues and Priority Queues CS Data Structures Mehmet H Gunes Modified from authors’ slides.
CMPT 225 Stacks.
Chapter 3 Stacks.
Stacks.
© 2006 Pearson Addison-Wesley. All rights reserved7 B-1 Chapter 7 (continued) Stacks.
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks.
Stacks Chapter Chapter Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions Checking for Balanced Parentheses,
Stack: Linked List Implementation Push and pop at the head of the list New nodes should be inserted at the front of the list, so that they become the top.
CHAPTER 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
Chapter 6 Stacks. © 2005 Pearson Addison-Wesley. All rights reserved6-2 The Abstract Data Type Specifications of an abstract data type for a particular.
Sorted Lists and Their Implementations Chapter 12 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Data Abstraction: The Walls
Queues and Priority Queues
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 6: Stacks Data Abstraction & Problem Solving with C++
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks.
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks (and a bit of generics for flavor)
Implementations of the ADT Stack Chapter 7 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 6 Stacks CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Chapter 7 Stacks I CS Data Structures I COSC 2006 April 22, 2017
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
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.
Chapter 7 Stacks. © 2004 Pearson Addison-Wesley. All rights reserved 7-2 The Abstract Data Type: Developing an ADT During the Design of a Solution Specifications.
Recursion as a Problem- Solving Technique Chapter 5 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CSE 373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
Tree Implementations Chapter 16 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 6: Stacks Data Abstraction & Problem Solving with C++
Chapter 6 B Stacks. © 2004 Pearson Addison-Wesley. All rights reserved6 B-2 Comparing Implementations All of the three implementations are ultimately.
Recursion as a Problem- Solving Technique Chapter 5 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
COMPSCI 105 SS 2015 Principles of Computer Science 09 ADT & Stacks.
Heaps Chapter 17 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
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.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Chapter 7 Stacks © 2006 Pearson Addison-Wesley. All rights reserved 7A-1.
Chapter 6 A Stacks. © 2004 Pearson Addison-Wesley. All rights reserved6 A-2 The Abstract Data Type: Developing an ADT During the Design of a Solution.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
CS Data Structures Chapter 6 Stacks Mehmet H Gunes
Stacks Chapter 6.
Chapter 5 Recursion as a Problem-Solving Technique
Revised based on textbook author’s notes.
Stacks.
CSE 373: Data Structures and Algorithms
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Visit for more Learning Resources
Chapter 13 Queues and Priority Queues
Chapter 6 Stacks.
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Stacks Chapter 5 Adapted from Pearson Education, Inc.
List Implementations Chapter 9
Stacks Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Lists Chapter 8.
Ch. 7 Stack 도입을 위한 예 “←” in keyboard input line
Figure 6.1 Stack of cafeteria dishes. Figure 6.1 Stack of cafeteria dishes.
Chapters 6 and 7 Stacks.
Data Structures and Algorithms 2/2561
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 7 © 2011 Pearson Addison-Wesley. All rights reserved.
CMPT 225 Lecture 7 – Stack.
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

Stacks Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Contents The Abstract Data Type Stack Simple Uses of a Stack Using Stacks with Algebraic Expressions Using a Stack to Search a Flight Map The Relationship Between Stacks and Recursion Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

The Abstract Data Type Stack Developing an ADT during the design of a solution Consider entering keyboard text  Mistakes require use of backspace abcdd  efgg  We seek a programming solution to read these keystrokes Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

The Abstract Data Type Stack Pseudocode of first attempt Requires  Add new item to ADT  Remove most recently added item Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Specifications for the ADT Stack We have identified the following operations:  See whether stack is empty.  Add a new item to stack.  Remove from the stack item added most recently.  Get item that was added to stack most recently. Stack uses LIFO principle  Last In First Out Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Specifications for the ADT Stack FIGURE 6-1 A stack of cafeteria plates Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Abstract Data Type: Stack A finite number of objects  Not necessarily distinct  Having the same data type  Ordered by when they were added Operations  isEmpty()  push(newEntry)  pop()  peek() Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Abstract Data Type: Stack View C++ Stack interface, Listing 6-1Listing 6-1 FIGURE 6-2 UML diagram for the class Stack Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.htm code listing files must be in the same folder as the.ppt files for these links to work

Axioms for the ADT Stack new Stack()).isEmpty() = true new Stack()).pop() = false new Stack()).peek() = error aStack.push(item)).isEmpty() = false aStack.push(item)).peek() = item aStack.push(item)).pop() = true Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Simple Uses of a Stack FIGURE 6-3 Traces of the algorithm that checks for balanced braces Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Simple Uses of a Stack Recognizing strings in a language Consider L = { s$s' : s is a possibly empty string of characters other than $, s' = reverse( s )} View algorithm to verify a string for a given language, Listing 6-AListing 6-A Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Using Stacks with Algebraic Expressions Evaluating postfix expressions FIGURE 6-4 The effect of a postfix calculator on a stack when evaluating the expression 2 * (3 + 4) Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Using Stacks with Algebraic Expressions Converting infix expressions to equivalent postfix expressions Possible pseudocode solution Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012

Using Stacks with Algebraic Expressions FIGURE 6-5 A trace of the algorithm that converts the infix expression a – ( b + c * d ) / e to postfix form Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012 View pseudocode algorithm that converts infix to postfix Listing 6-B

End Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012