Lecture 21 Stacks and Queues Richard Gesick.

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

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.
Stacks, Queues, and Linked Lists
Stack & Queues COP 3502.
1 Stack and Queue. 2 Stack In Out ABCCB Data structure with Last-In First-Out (LIFO) behavior.
CS Data Structures II Review COSC 2006 April 14, 2017
COMP 103 Linked Stack and Linked Queue.
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.
TCSS 342, Winter 2005 Lecture Notes
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
1 Lecture 26 Abstract Data Types – IV Overview  The List ADT  Implementing Stacks as Linked List  Linked List Implementation of Queues .  Preview:
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 and Queues Introduction to Computing Science and Programming I.
Dr. Salah Hammami KSU-CCIS-CS Ahmad Al-Rjoub CSC 113 King Saud University College of Computer and Information Sciences Department of Computer Science Chapter.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
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.
The Queue Data Structure Mugurel Ionu Andreica Spring 2012.
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.
Queue Queue – First In / First Out (FIFO) data structure that supports two operations: push for adding new element at the end of the queue pop for removing.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
Lecture 20 Stacks and Queues. Stacks, Queues and Priority Queues Stacks – first-in-last-out structure – used for function evaluation (run-time stack)
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
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.
Queues 1. Queue  a queue represents a sequence of elements where elements can be added at the back of the sequence and removed from the front of the.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
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.
Programming Abstractions
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.
COSC160: Data Structures: Lists and Queues
QueueStack CS1020.
Stacks and Queues.
September 29 – Stacks and queues
Chapter 15 Lists Objectives
Sequences 8/1/2018 4:38 AM Linked Lists Linked Lists.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
Stack and Queue.
Stacks and Queues.
Data Structures and Database Applications Queues in C#
Queues A queue is a data structure that is similar in spirit to a fair line. As you can see in this photo, the first dog in line can expect to be the first.
Building Java Programs
Stacks and Queues.
CSE 214 – Computer Science II Stacks
Stacks and Queues CLRS, Section 10.1.
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.
Stacks and Queues 1.
Recall: stacks and queues
More Data Structures (Part 1)
Visit for more Learning Resources
Lecture 2: Stacks and Queues
Lecture 16 Stacks and Queues CSE /26/2018.
Abstract Data Type (ADT)
Fundaments of Game Design
Using a Queue Chapter 8 introduces the queue data type.
Recall: stacks and queues
Using a Queue Chapter 8 introduces the queue data type.
CS210- Lecture 6 Jun 13, 2005 Announcements
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Lecture 16 Stacks and Queues CSE /26/2018.
Revised based on textbook author’s notes.
Stacks and Queues.
Lecture 9: Stack and Queue
Presentation transcript:

Lecture 21 Stacks and Queues Richard Gesick

Stacks Implement a first-in-last-out behavior Push() to add an element Pop() to remove an element Add and remove from the same side of the internal data structure Easiest to add/remove from the front if implemented as a linked list internally Peek() returns the top element without removing it from the stack

Stacks C# stack is generic. Consider: Stack <string> myStack= new Stack>string>(); myStack.Push(“hello”); myStack.Push(“fun”); myStack.Push(“great”); Stack state? string t=myStack.Pop(); string s= myStack.Peek(); What is stored in s, t and what is left in the stack?

Stacks Which data structure would you pick to implement a Stack? Why?

Queues Implement a first-in-first-out behavior Enqueue() to add an element Dequeue() to remove an element Add and remove from the opposite sides of the internal data structure If we maintain a list-tail reference, then we can add to the end and remove from the front, each having constant - O(1) - time

Queues C# Queue is generic. Consider: State of the queue? Queue<int> q= new Queue<int>(); q.Enqueue(5); q.Enqueue(7); q.Enqueue(1); State of the queue? int a= q.Dequeue(); int b= q.Dequeue(); What is stored in a, b and what left in the queue?

Queues Which data structure would you pick to implement a Queue? Why?