Basic Data Types Queues

Slides:



Advertisements
Similar presentations
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Advertisements

Queues A waiting line that grows by adding elements to its end and shrinks by taking elements from its front Line at the grocery store Cars in traffic.
CHAPTER 7 Queues.
CS Data Structures II Review COSC 2006 April 14, 2017
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Queues.
Data Structures from Cormen, Leiserson, Rivest & Stein.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
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.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Data Structures - Queues
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
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’
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
Stacks And Queues Chapter 18.
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.
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.
Stacks Queues Introduction to Trees. Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that.
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.
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.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
Queue ADT for lining up politely. COSC 2006 queue2 Queue – simple collection class  first-in first-out (FIFO) structure insert new elements at one end.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
Data Structures Intro2CS – week Stack ADT (Abstract Data Type) A container with 3 basic actions: – push(item) – pop() – is_empty() Semantics: –
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
Chapter 7 Stacks © 2006 Pearson Addison-Wesley. All rights reserved 7A-1.
Linked Data Structures
Review Array Array Elements Accessing array elements
Cpt S 122 – Data Structures Abstract Data Types
Elementary data structures
Chapter 12 – Data Structures
COSC160: Data Structures: Lists and Queues
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
QueueStack CS1020.
Chapter 15 Lists Objectives
Sequences 8/1/2018 4:38 AM Linked Lists Linked Lists.
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
Java collections library
Data Structures 1 1.
8-1.
HW-6 Deadline Extended to April 27th
Topic 16 Queues Adapted from Mike Scott’s materials.
i206: Lecture 11: Stacks, Queues
CMSC 341 Lecture 5 Stacks, Queues
Principles of Computing – UFCFA3-30-1
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
8-1.
Queue, Deque, and Priority Queue Implementations
Queues.
Arrays and Linked Lists
A Data Structure Bestiary
Topic 16 Queues "FISH queue: n.
A Data Structure Bestiary
Doubly linked lists Idea: same as singly linked list, but each node also points to the previous: Can optionally also have a pointer to the tail, so we.
Queues: Implemented using Arrays
Queues A first-in, first-out or FIFO data structure.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Data Structures and Algorithms for Information Processing
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Stacks and Queues.
Abstract Data Type (ADT)
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Stacks, Queues, and Deques
Lecture 9: Stack and Queue
Presentation transcript:

Basic Data Types Queues Richard Newman Based on Sedgewick and Wayne 1

Stacks and Queues Stacks Dynamic Resizing Queues Generics Iterators Applications 2

Fundamental data types • Values: sets of objects • Operations: insert, remove, test if empty. • Intent is clear when we insert. • Which item do we remove? 3

Fundamental data types Stack: Remove the item most recently added. (*LIFO – “last in first out”) Analogy: Cafeteria trays. Web surfing. Queue: Remove the item least recently added. (*FIFO – “first in first out”) Analogy: Grocery store checkout line. 4

Queue API Public class Queue: Can be any type (stay tuned) ENQUEUE Queue ( ) Create an empty queue Void enqueue (String S) Insert a new item onto stack String dequeue ( ) Remove and return the item least recently added Boolean isEmpty ( ) Is the queue empty? ENQUEUE DEQUEUE NEWEST OLDEST 5

Queue: linked-list implementation Can it be done with a singly linked list? a) No – not efficiently b) c) d) IDK Most recent Least recent of best the was it Most recent Least recent of best the was it

Dequeue: linked-list implementation tail head of best the was it String item = head.item; “it” tail head of best the was it head = head.next; tail head of best the was return item; “it”

Enqueue: linked-list implementation tail oldTail head best the was it Node oldTail = tail; tail oldTail head of best the was it tail = new Node(); tail.item = “of”; tail oldTail head of best the was it oldTail.next = tail;

Queues: array implementation Use array q[ ] to store items in queue enqueue() add new item at q[++tail] dequeue() remove item from q[head++] Update (increment) head and tail modulo capacity q[] it was the best of head 1 2 3 4 5 tail

Queues: array implementation enqueue() add new item at q[++tail] q[] it was the best of times 1 2 3 4 5 6 head tail

Queues: array implementation dequeue() remove item from q[head++] q[] it was the best of times 1 2 3 4 5 6 head tail

Queues: array implementation Update (increment) head and tail modulo capacity (7) q[] was was the best of times it 1 2 3 4 5 6 head tail

Dynamic Resizing Queues: array implementation Arrays are instantiated with a specific size Q: How to grow queue when capacity reached? Q: When to shrink array when queue shrinks? A: What do you think? :)

Next: Generics