Stack Implementations Chapter 22 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.

Slides:



Advertisements
Similar presentations
Stacks Chapter 21 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Advertisements

Dictionary Implementations Chapter 18 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
A Bag Implementation that Links Data Chapter 3 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A List Implementation That Links Data Chapter 6 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Faster Sorting Methods Chapter 12 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Creating Classes from Other Classes Chapter 2 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Stacks A stack is a data structure that only allows items to be inserted and removed at one end We call this end the top of the stack The other end is.
Completing the Linked Implementation of a List Chapter 7 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Graphs Chapter 30 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Data Structures & Algorithms
List Implementations That Use Arrays Chapter 5 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Stack Implementations Chapter Chapter Contents A Linked Implementation An Array-Based Implementation A Vector-Based Implementation.
Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Announcements.
Iterators Chapter 8 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Queue, Deque, and Priority Queue Implementations Chapter 24 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
The Efficiency of Algorithms Chapter 9 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Trees Chapter 25 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Searching Chapter 16 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Inheritance and Lists Chapter 14 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Stack Implementations Chapter Chapter Contents A Linked Implementation An Array-Based Implementation A Vector-Based Implementation.
Chapter 6 Stacks. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2 Chapter Objectives Examine stack processing Define a stack abstract.
Mutable, Immutable, and Cloneable Objects Chapter 15 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Chapter 3 Array-Based Implementations CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Queue, Deque, and Priority Queue Implementations Chapter 11 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Queues, Deques, and Priority Queues Chapter 23 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
An Introduction to Sorting Chapter 11 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Hashing as a Dictionary Implementation Chapter 20 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Graph Implementations Chapter 31 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
A Binary Search Tree Implementation Chapter 27 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Dictionaries Chapter 17 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
© 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.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
Chapter 6 Stacks. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Examine stack processing Define a stack abstract.
Lists Chapter 4 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
Stack Implementations Chapter 6 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Heap Implementation Chapter 26 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Chapter 5 Array-Based Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Iterators (short version) Chapter 15 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
A Bag Implementation that Links Data Chapter 3 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Balanced Search Trees (partial) Chapter 29 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall - Edited by Nadia Al-Ghreimil.
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Lists and Sorted Lists: various implementations Slides by Nadia Al-Ghreimil adopted from Steve Armstrong LeTourneau University Longview, TX  2007, 
Click to edit Master text styles Stacks Data Structure.
Recursion Chapter 10 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Recursion Chapter 10 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Slides by Steve Armstrong LeTourneau University Longview, TX
Stack Implementations
List Implementations Chapter 9
Iterators (short version)
Slides by Steve Armstrong LeTourneau University Longview, TX
Slides by Steve Armstrong LeTourneau University Longview, TX
Slides by Steve Armstrong LeTourneau University Longview, TX
Iterators (partial) Chapter 8 Slides by Nadia Al-Ghreimil
List Implementations that Use Arrays
A List Implementation That Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Balanced Search Trees (partial)
Stack Implementations
A List Implementation That Links Data
List Implementations that Use Arrays
Stack Implementations
© 2016 Pearson Education, Ltd. All rights reserved.
© 2016 Pearson Education, Ltd. All rights reserved.
A List Implementation that Links Data
Queue, Deque, and Priority Queue Implementations
Presentation transcript:

Stack Implementations Chapter 22 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Chapter Contents A Linked Implementation An Array-Based Implementation A Vector-Based Implementation

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A Linked Implementation When using a chain of linked nodes to implement a stack  The first node should reference the stack's top Fig A chain of linked nodes that implements a stack.

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A Linked Implementation View source code of class for stack implemented by linked listsource code Note methods  push  peek  pop  isEmpty  clear

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A Linked Implementation Fig (a) A new node that references the top of the stack; (b) the new node is now at the top of the stack.

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A Linked Implementation Fig The stack (a) before the first node in the chain is deleted

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A Linked Implementation Fig The stack (b) after the first node in the chain is deleted

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X An Array-Based Implementation When using an array to implement a stack  The array's first element should represent the bottom of the stack  The last occupied location in the array represents the stack's top This avoids shifting of elements of the array if it were done the other way around

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X An Array-Based Implementation Fig An array that implements a stack; its first location references (a) the top of the stack; (b) the bottom of the stack

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X An Array-Based Implementation View source code for array-based implementation of the ADT stacksource code Note methods  push  peek  pop  isEmpty

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X An Array-Based Implementation Fig Another array-based stack after top removed by (a) decrementing topIndex ;

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X An Array-Based Implementation Fig Another array-based stack after top removed by (b) setting stack[topIndex]=null and then decrementing topIndex

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A Vector-Based Implementation When using a vector to implement a stack  Vector's first element should represent the bottom of the stack  Last occupied location in the vector represents the stack's top Based on an array that can be expanded dynamically  Performance similar to array-based implementation

Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X A Vector-Based Implementation View source code for vector-based implementation of the ADT stacksource code Note methods  push  peek  pop  isEmpty  clear