Stacks and Queues. Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about.

Slides:



Advertisements
Similar presentations
VCE Software Development Theory Slideshows By Mark Kelly Vceit.com Stacks.
Advertisements

STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Data Structure HKOI training /4/2010 So Pak Yeung.
Data Structures Part 2 Stacks, Queues, Trees, and Graphs Briana B. Morrison CSE 1302C Spring 2010.
Stack & Queues COP 3502.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Data Structures & Algorithms
Data Structures: Lists i206 Fall 2010 John Chuang Some slides adapted from Glenn Brookshear, Brian Hayes, or Marti Hearst.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
COMP 110 Introduction to Programming Mr. Joshua Stough.
Data Structures from Cormen, Leiserson, Rivest & Stein.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Algorithms and Data Structures Representing Sequences by Arrays and Linked Lists.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Sorting, Stacks, Queues Bryce Boe 2013/11/06 CS24, Fall 2013.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Stacks, Queues Bryce Boe 2013/07/30 CS24, Summer 2013 C.
Stacks and Queues Introduction to Computing Science and Programming I.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
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,
CMSC 202 Stacks and Queues. What’s a Queue? A queue is a linear collection of homogeneous data in which items added to the queue must be placed at the.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
Stacks And Queues Chapter 18.
Arrays and Collections Tonga Institute of Higher Education.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.
Data-structure-palooza Checkout DataStructures from SVN.
Linear Data Structures
CSCI 62 Data Structures Dr. Joshua Stough October 7, 2008.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
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.
3/3/20161 Stacks and Queues Introduction to Data Structures Ananda Gunawardena.
Lecture 21 Data Structures, Algorithms and Complexity Stacks and Queues GRIFFITH COLLEGE DUBLIN.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
1 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
Lecture 16 Stacks and Queues Richard Gesick. Sample test questions 1.Write a definition for a Node class that holds a number. 2.Write a method that sums.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
G64ADS Advanced Data Structures
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Lecture 7 Queues Stacks Trees.
COSC160: Data Structures: Lists and Queues
Chapter 15 Lists Objectives
Data Structures and Database Applications Queues in C#
i206: Lecture 11: Stacks, Queues
Principles of Computing – UFCFA3-30-1
i206: Lecture 10: Lists, Stacks, Queues
Stacks, Queues, and Deques
Lecture 21 Stacks and Queues Richard Gesick.
ITEC 2620M Introduction to Data Structures
CSE 214 – Computer Science II Stacks
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 (ADT)
Lecture 16 Stacks and Queues CSE /26/2018.
Lecture 9: Stack and Queue
Presentation transcript:

Stacks and Queues

Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about any kind of data Queues – First In, First Out (FIFO) – Like waiting in line Stacks – First In, Last Out (FILO) – Like a stack of trays Stacks and Queues

Stacks Three primary operations – Push() – put new data on the top of the stack – Pop() – remove data from the top of the stack – Peek() – get a copy of the data on the top of the stack Useful – our function stack! – stack of cards, tiles, loot, etc…

Example (pushing) 5 Note: could use a linked list also

Example (pushing) 5 11

Example (pushing)

Example (pushing)

Example (current stack)

Example (peeking)

Example (popping)

Example (pushing)

Example (popping)

Example (popping)

Example (popping) 5 11

Example (popping) 5 FILO

Queues Two primary operations – Enqueue() – put new data at the end of the queue – Dequeue() – remove data from the beginning of the queue – Peek() – yes, its still there… Useful – Enforcing fairness (waitlist at SPSU) – Player turns during a round

Example

Example (enqueue a 5) 5

Example 5

Example (enqueue an 11) 5 11

Example 511

Example (enqueue a -6)

Example

Example (dequeue)

Example (dequeue)

Example (dequeue) FIFO

Example (dequeue) 11 -6

Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list Queues are FIFO Stacks are FILO Which data structure is LILO? Which one is LIFO? Summary