Tonga Institute of Higher Education

Slides:



Advertisements
Similar presentations
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Advertisements

Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials Stack and Queues.
Stacks and Queues. 2 Stack and Queue ADT’s You should understand How are they different philosophically from arrays What are they used for How do you.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
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.
Data Structures & Algorithms
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Stacks (Revised and expanded from CIT 591). What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on.
Stacks. 2 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.
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.
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.
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.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Data Structures Data structures permit the storage of related data for use in your program. –Arrays.
Digital Electronics Data Structures LISP
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
Stacks and Queues Introduction to Computing Science and Programming I.
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
Stack and Queues. A Different Kind of Structure Some of the data storage structure such as Arrays, linked lists, trees, and so on are appropriate for.
Queues Tonga Institute of Higher Education. Definitions Queue - A data structure that stores a number of items. The first item entered into a queue is.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 3.
Arrays and Collections Tonga Institute of Higher Education.
Data Structures & Algorithms
Chapter 4 Stacks and Queues © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Click to edit Master text styles Stacks Data Structure.
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
Stack ADT (Abstract Data Type) N …
Stack: a Linked Implementation
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Queues.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Chapter 12 – Data Structures
COSC160: Data Structures: Lists and Queues
CSCI 3333 Data Structures Stacks.
September 29 – Stacks and queues
Sequences Saturday, 02 June 2018
Adding and subtracting decimals
Cinda Heeren / Geoffrey Tien
Stacks A stack is a data structure that is similar in spirit to a pile of cafeteria trays. Think about the trays in the dining halls: when the dining staff.
Building Java Programs Chapter 14
Stack Data Structure, Reverse Polish Notation, Homework 7
Stack and Queues.
Pointers and Linked Lists
Implementations of the ADT Stack
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Stacks.
Stacks, Queues, and Deques
Data Structures and Database Applications Stacks in C#
More About Stacks: Stack Applications
1. Be able to add and subtract rational functions.
Stacks, Queues, and Deques
Sequences Friday, 23 November 2018
CSE 214 – Computer Science II Stacks
Stacks: Implemented using Linked Lists
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
Data Structures and Algorithms for Information Processing
Abstract Data Type Abstract Data Type as a design tool
Abstract Data Types and Stacks
Stacks, Queues, and Deques
Sequences Wednesday, 22 May 2019
More About Stacks: Stack Applications
Stacks.
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
Abstract Data Types Stacks CSCI 240
Lecture 9: Stack and Queue
Stack Implementations
CHAPTER 3: Collections—Stacks
Presentation transcript:

Tonga Institute of Higher Education Stacks Tonga Institute of Higher Education

The Mail Analogy When we get mail, we put all of our letters in a basket. Then, when we have time, we look at each letter starting from the top of the stack. After we process the letter, we put it away and look at the next one until we are at the bottom of the stack Warning: This “do the top one first” approach works well as long as you are able to process all the mail. If you can’t, there is a danger that letters on the bottom of the stack won’t be examined for months.

The Restaurant Analogy Think of a stack of plates in a restaurant. When the plates are being stacked, they are added one on top of each other. It doesn't make much sense to put each plate on the bottom of the pile, as that would be far more work, and would accomplish nothing over stacking them on top of each other. Similarly when a plate is taken, it is usually taken from the top of the stack.

Definitions Stack – A data structure that stores a number of items. The last item entered into a stack is the first item to be removed Push – The act of adding an item to a stack Pop – The act of removing an item from the top of a stack Peek – The act of viewing the value of the item on top of the stack. Note: You cannot see the values for items under the top item. LIFO – Last in First Out – Sometimes used to describe a stack

Push - Add

Pop - Remove

Stack Implemented as an Array 1st in line 2nd in line 3rd in line 1 2 3 4 5 We can implement a stack using an array Each cell of the array represents a thing in the stack The bottom of stack is on the left The top of the stack is on the right

Stack Considerations Stack Size – Can be set when the stack is created Errors: We try to push (add an item) when the stack is full We try to pop (remove an item) when the stack is empty

Presentation Stack Applet

Presentation Stack Code

Efficiency of Stacks Items can be pushed and popped in constant O(1) time This time is not dependent on the number of items in the stack so it is very fast No comparisons or moves are necessary