Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 8 Ming Li Department of.

Slides:



Advertisements
Similar presentations
Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample.
Advertisements

Computer Science 112 Fundamentals of Programming II Queues and Priority Queues.
Queue Definition Ordered list with property: –All insertions take place at one end (tail) –All deletions take place at other end (head) Queue: Q = (a 0,
Lec 7 Sept 17 Finish discussion of stack infix to postfix conversion Queue queue ADT implementation of insert, delete etc. an application of queue.
Data Structure (Part I) Stacks and Queues. Introduction to Stack An stack is a ordered list in which insertion and deletions are made at one end. –The.
1 Stack and Queue. 2 Stack In Out ABCCB Data structure with Last-In First-Out (LIFO) behavior.
Data Structures for Media Queues. Queue Abstract Data Type Queue Abstract Data Type Sequential Allocation Sequential Allocation Linked Allocation Linked.
CHAPTER 7 Queues.
ADT Queue 1. What is a Queue? 2. STL Queue 3. Array Implementation of Queue 4. Linked List Implementation of Queue 5. Priority Queue.
Queues Briana B. Morrison Adapted from Alan Eugenio.
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 10 Ming Li Department of.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 14 Ming Li Department of.
CS 206 Introduction to Computer Science II 03 / 06 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 17 / 2008 Instructor: Michael Eckmann.
Introduction to Data Structure, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Introduction of Concepts Ming Li.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 10 Ming Li Department of.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 16 / 2009 Instructor: Michael Eckmann.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 7 Ming Li Department of.
Lecture 11 Sept 26, 2011 Goals convert from infix to postfix.
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
Priority Queues Briana B. Morrison Adapted from Alan Eugenio Sell100IBM$122 Sell300IBM$120 Buy500IBM$119 Buy400IBM$118.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
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.
Sorting, Stacks, Queues Bryce Boe 2013/11/06 CS24, Fall 2013.
Main Index Contents 11 Main Index Contents Week 4 – Stacks.
1 Stacks Stack Examples Stack API More Examples/Uses Base Conversion Activation Records RPN Implementing a Stack Stacks.
Containers Overview and Class Vector
1 CSC 222: Computer Programming II Spring 2004 Pointers and linked lists  human chain analogy  linked lists: adding/deleting/traversing nodes  Node.
TECH Computer Science Data Abstraction and Basic Data Structures Improving efficiency by building better  Data Structure Object IN  Abstract Data Type.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
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.
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.
Data Structures Using C++
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
EC-211 DATA STRUCTURES LECTURE 9. Queue Data Structure An ordered group of homogeneous items or elements. Queues have two ends: – Elements are added at.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
Adapted from Data Structures with C++ using STL: Ford, Topp CS 362: Queues Dr. Nazli Mollah Overview of Lecture  Introduction  The Queue ADT  The Radix.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
1 Queues Queue API Application: Radix Sort Implementation: Using Deque Using Deque Circular Array Circular Array Priority Queue Priority Queue API Implementation.
Computer Engineering Rabie A. Ramadan Lecture 6.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 4 Ming Li Department of Computer.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
Main Index Contents 11 Main Index Contents Sets Defined by a key along with other data Sets Defined by a key along with other data Key-Value Data Key-Value.
Cpt S 122 – Data Structures Abstract Data Types
CC 215 Data Structures Queue ADT
Briana B. Morrison Adapted from Alan Eugenio
Stacks and Queues.
Programming Abstractions
Queues Chapter 4.
Algorithms and Data Structures
Stack and Queue.
Associative Structures
Programming Abstractions
Queues Jyh-Shing Roger Jang (張智星)
Containers: Queue and List
Visit for more Learning Resources
CSCS-200 Data Structure and Algorithms
The List Container and Iterators
Applications of Arrays
Data Structures & Programming
Presentation transcript:

Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 8 Ming Li Department of Computer Science California State University, Fresno Spring 2007

Introduction to Data Structure, Fall 2006 Slide- 2 California State University, Fresno Grocery Store Checkout: A Model for a Queue

Introduction to Data Structure, Fall 2006 Slide- 3 California State University, Fresno Queue - Illustration A Queue is a FIFO (First in First Out) Data Structure. Elements are inserted in the Rear of the queue and are removed at the Front.

Introduction to Data Structure, Fall 2006 Slide- 4 California State University, Fresno queue(); Create an empty queue. bool empty() const; Check whether the queue is empty. Return true if it is empty and false otherwise. T&l front(); Return a reference to the value of the item at the font of the queue. Precondition: The queue is not empty. Queue - Operations

Introduction to Data Structure, Fall 2006 Slide- 5 California State University, Fresno const T& front() const; Constant version of front(). void pop(); Remove the item from the front of the queue. Precondition:The queue is not empty. Postcondition: The element at the front of the queue is the element that was added immediately after the element just popped or the queue is empty. Queue - Operations

Introduction to Data Structure, Fall 2006 Slide- 6 California State University, Fresno 6 void push(const T& item); Insert the argument item at the back of the queue. Postcondition:The queue has a new item at the back int size() const; Return the number of elements in the queue. Queue - Operations

Introduction to Data Structure, Fall 2006 Slide- 7 California State University, Fresno Queue - The Radix Sort Order ten 2 digit numbers in 10 bins from smallest number to largest number. Requires 2 calls to the sort Algorithm. Initial Sequence: Pass 0: Distribute the cards into bins according to the 1's digit (10 0 ).

Introduction to Data Structure, Fall 2006 Slide- 8 California State University, Fresno Queue - The Radix Sort Final Sequence: Pass 1: Take the new sequence and distribute the cards into bins determined by the 10's digit (10 1 ).

Introduction to Data Structure, Fall 2006 Slide- 9 California State University, Fresno Queue - Implementation

Introduction to Data Structure, Fall 2006 Slide- 10 California State University, Fresno The Bounded queue Famous producer/consumer problem

Introduction to Data Structure, Fall 2006 Slide- 11 California State University, Fresno The Bounded queue Qback = (qback + 1)% MAXQSIZE Qfront = (qfront + 1)% MAXQSIZE How to know if a queue is full?

Introduction to Data Structure, Fall 2006 Slide- 12 California State University, Fresno Priority Queue A Special form of queue from which items are removed according to their designated priority and not the order in which they entered. Items entered the queue in sequential order but will be removed in the order #2, #1, #4, #3.

Introduction to Data Structure, Fall 2006 Slide- 13 California State University, Fresno priority_queue(); Create an empty priority queue. Type T must implement the operator <. bool empty() const; Check whether the priority queue is empty. Return true if it is empty, and false otherwise. void pop(); Remove the item of highest priority from the queue. Precondition:The priority queue is not empty. Postcondition:The priority queue has 1 less element Priority Queue - Operations

Introduction to Data Structure, Fall 2006 Slide- 14 California State University, Fresno void push(const T& item); Insert the argument item into the priority queue. Postcondition: The priority queue contains a new element. int size() const; Return the number of items in the priority queue. T& top(); Return a reference to the item having the highest priority. Precondition: The priority queue is not empty. const T& top(); Constant version of top(). Priority Queue - Operations

Introduction to Data Structure, Fall 2006 Slide- 15 California State University, Fresno Queue - Traversal q.pop(); while(!q.empty()) q.pop();

Introduction to Data Structure, Fall 2006 Slide- 16 California State University, Fresno Queue - Search if(q.front() != 6) q.pop(); while(!q.empty() && q.front() != 6) q.pop();