Implementations of the ADT Stack

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures II Review COSC 2006 April 14, 2017
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Stacks.
Sorted Lists and Their Implementations Chapter 12 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks.
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.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
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:
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 3.
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.
Lab 6 Stack ADT. OVERVIEW The stack is one example of a constrained linear data structure. In a stack, the elements are ordered from most recently added.
Copyright © Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
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 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
Link Based Implementations
Section 3.7 Linked-Based Implementations
Stack: a Linked Implementation
Stacks II David Lillis School of Computer Science and Informatics
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.
CSCI 3333 Data Structures Stacks.
Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.
A Bag Implementation that Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Chapter 16 Tree Implementations
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Stack Implementations
Chapter 12 Sorted Lists and their Implementations
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Queue and Priority Queue Implementations
Chapter 14: Queue and Priority Queue Implementations
List Implementations Chapter 9
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Tonga Institute of Higher Education
Data Abstraction: The Walls
List Implementations Chapter 9.
Array-Based Implementations
Sorted Lists and Their Implementations
CSC 143 Stacks [Chapter 6].
Stack Implementations
Figure 7.1 Some queue operations. Figure 7.1 Some queue operations.
Chapter 7 Implementations of the ADT Stack
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
5.3 Implementing a Stack Chapter 5 – The Stack.
Stack Implementations
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

Implementations of the ADT Stack Chapter 7

An Array-Based Implementation FIGURE 7-1 Using an array to store a stack’s entries

An Array-Based Implementation Listing 7-1 The header file for an array-based stack

An Array-Based Implementation Listing 7-1 The header file for an array-based stack

An Array-Based Implementation LISTING 7-2 The implementation file for an array-based stack

An Array-Based Implementation LISTING 7-2 The implementation file for an array-based stack

An Array-Based Implementation LISTING 7-2 The implementation file for an array-based stack

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

A Link-Based implementation FIGURE 7-2 A link-based implementation of a stack

A Link-Based implementation LISTING 7-3 The header file for the class LinkedStack

A Link-Based implementation LISTING 7-3 The header file for the class LinkedStack

A Link-Based implementation LISTING 7-4 The implementation file for the class LinkedStack

A Link-Based implementation LISTING 7-4 The implementation file for the class LinkedStack

A Link-Based implementation LISTING 7-4 The implementation file for the class LinkedStack

A Link-Based implementation LISTING 7-4 The implementation file for the class LinkedStack

A Link-Based implementation LISTING 7-4 The implementation file for the class LinkedStack

A Link-Based implementation LISTING 7-4 The implementation file for the class LinkedStack

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

Implementations That Use Exceptions LISTING 7-5 The header file for the class PrecondViolatedExcep

Implementations That Use Exceptions LISTING 7-6 Implementation file for the class PrecondViolatedExcep

End Chapter 7