Chapter 7 Implementations of the ADT Stack

Slides:



Advertisements
Similar presentations
Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Advertisements

CS Data Structures II Review COSC 2006 April 14, 2017
Chapter 13 Queues and Priority Queues CS Data Structures Mehmet H Gunes Modified from authors’ slides.
CS Data Structures Chapter 8 Lists Mehmet H Gunes
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Stack Implementations Chapter 22 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
C++ Interlude 2 Pointers, Polymorphism, and Memory Allocation
Chapter 3 Array-Based Implementations CS Data Structures Mehmet H Gunes Modified from authors’ slides.
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.
Bags Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
1 Linked Stack Chapter 4. 2 Linked Stack We can implement a stack as a linked list. Same operations. No fixed maximum size. Stack can grow indefinitely.
Stacks. A stack is a data structure that holds a sequence of elements and stores and retrieves items in a last-in first- out manner (LIFO). This means.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Namespaces & Exceptions Adapted from Ch. 3 slides of Data Abstraction:
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Stack Implementations Chapter 6 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Copyright © Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Interlude 1 C++ Classes CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
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.
Chapter 4 Link Based Implementations
Section 3.7 Linked-Based Implementations
CS Data Structures Chapter 6 Stacks Mehmet H Gunes
Stack: a Linked Implementation
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
C++ Programming:. Program Design Including
Chapter 5 Linked Lists © 2006 Pearson Addison-Wesley. All rights reserved.
© 2017 Pearson Education, Hoboken, NJ. All rights reserved
Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.
CS Data Structures Chapter 8 Lists Mehmet H Gunes
Pointers, Polymorphism, and Memory Allocation
Chapter 1 Data Abstraction: The Walls
Processing Data in External Storage
A Bag Implementation that Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Chapter 16 Tree Implementations
Chapter 13 Queues and Priority Queues
Implementations of the ADT Stack
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 4 Link Based Implementations
Stack Implementations
Chapter 12 Sorted Lists and their Implementations
Chapter 3 Array-Based Implementations
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Queue and Priority Queue Implementations
Chapter 14: Queue and Priority Queue Implementations
Dictionaries and Their Implementations
Copyright ©2012 by Pearson Education, Inc. All rights reserved
CS Data Structures Chapter 17 Heaps Mehmet H Gunes
List Implementations Chapter 9.
CS Data Structures Chapter 17 Heaps Mehmet H Gunes
Chapter 16 Tree Implementations
Array-Based Implementations
Sorted Lists and Their Implementations
Stack Implementations
Array-Based Implementations
Stacks Chapter 5.
Chapter 5 Linked Lists © 2006 Pearson Addison-Wesley. All rights reserved.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.
Queues and Priority Queue Implementations
Chapter 7 © 2011 Pearson Addison-Wesley. All rights reserved.
Abstract Data Types Stacks CSCI 240
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Stack Implementations
© 2016 Pearson Education, Ltd. All rights reserved.
Introduction to Classes and Objects
Presentation transcript:

Chapter 7 Implementations of the ADT Stack CS 302 - Data Structures Mehmet H Gunes Modified from authors’ slides

An Array-Based Implementation Using an array to store a stack’s entries © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

An Array-Based Implementation The header file for an array-based stack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

An Array-Based Implementation The header file for an array-based stack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

An Array-Based Implementation The implementation file for an array-based stack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

An Array-Based Implementation The implementation file for an array-based stack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

An Array-Based Implementation The implementation file for an array-based stack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

An Array-Based Implementation Protecting the ADT’s walls Implement stack as a class Declaring items and top as private Note push receives newEntry as constant reference argument push uses newEntry as an alias … no copy made © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

A Link-Based implementation A link-based implementation of a stack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

A Link-Based implementation The header file for the class LinkedStack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

A Link-Based implementation The header file for the class LinkedStack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

A Link-Based implementation The implementation file for the class LinkedStack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

A Link-Based implementation The implementation file for the class LinkedStack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

A Link-Based implementation The implementation file for the class LinkedStack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

A Link-Based implementation The implementation file for the class LinkedStack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

A Link-Based implementation The implementation file for the class LinkedStack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

A Link-Based implementation The implementation file for the class LinkedStack © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Implementations That Use Exceptions Method peek does not expect client to look at top of an empty stack assert statement merely issues error message, and halts execution Consider having peek throw an exception Listings follow on next slides © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Implementations That Use Exceptions The header file for the class PrecondViolatedExcep © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Implementations That Use Exceptions Implementation file for the class PrecondViolatedExcep © 2017 Pearson Education, Hoboken, NJ.  All rights reserved