Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A4 – Basic Data Structures – Continued (Queues)

Slides:



Advertisements
Similar presentations
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Advertisements

Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
1 Data Structures CSCI 132, Spring 2014 Lecture 8 Implementing Queues.
CHAPTER 4 QUEUE CSEB324 DATA STRUCTURES & ALGORITHM.
Queues CS-212 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed in their.
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.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 18 Stacks.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
STACKS AND QUEUES. A LINKED LIST IMPLEMENTATION OF A QUEUE data next data next NULL data next cnt front rear queue node Queue: First-In-First-Out (FIFO)
Queue Overview Queue ADT Basic operations of queue
Data Structures Chapter 3 Queues Andreas Savva. 2 Queues A data structure modeled after a line of people waiting to be served. A data structure modeled.
1 Lectures on data structures and C 3ed CS(CSI33) By, CHANDRASHEKAR A.M.
CSE1303 Part A Data Structures and Algorithms Lecture A3 – Basic Data Structures (Stacks)
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A6 – Dynamic Memory.
CSE1303 Part A Data Structures and Algorithms Lecture A7 – Nodes and Linked Structures.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A15 – Hash Tables: Collision Resolution.
Topic 3 Basic Data Structures continued CSE1303 Part A Data Structures and Algorithms.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A2 – Pointers (Revision)
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
CSE1303 Part A Data Structures and Algorithms Lecture A13 – Binary Search Trees (Information Retrieval)
CSE1303 Part A Data Structures and Algorithms Lecture A11 – Recursion.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A8 – Linked Stacks and Linked Queues.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A9 – Linked Lists.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A10 – Elementary Algorithms (Revision)
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A11 – Recursion.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
CSE1303 Part A Data Structures and Algorithms Lecture A9 – Linked Lists.
Lecture 11 Sept 26, 2011 Goals convert from infix to postfix.
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.
Lists CSE1303 Part A Data Structures and Algorithms.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A5 – Basic Data Structures – Continued (Lists)
Basic Data Structures – Continued (Lists). 2 Basic Data Types Stack Last-In, First-Out (LIFO) initialize, push, pop, status Queue First-In, First-Out.
Queues Chapter 3. Objectives Introduce the queue abstract data type. – Queue methods – FIFO structures Discuss inheritance in object oriented programming.
EASTERN MEDITERRANEAN UNIVERSITY Stacks EENG212 –Algorithms and Data Structures.
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
The Queue Data Structure Mugurel Ionu Andreica Spring 2012.
Queues EENG212 Algorithm And Data Structures. DEFINITION OF QUEUE A Queue is an ordered collection of items from which items may be deleted at one end.
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.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 18: Stacks and Queues.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
CE 221 Data Structures and Algorithms
Basic Data Structures (Stacks). 2 Basic Data Structures Stacks Queues Lists.
1 Data Structures CSCI 132, Spring 2016 Notes13 Queues as Linked Lists, Polynomial Arithmetic.
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
الطابور QUEUE (abstract data type) واحد من هياكل البيانات الخطية الشائعة الاستخدام داخل البرامج. يحتوي علي عناصر من نفس النوع. من أنواع البيانات الخطية.
Queues Manolis Koubarakis Data Structures and Programming Techniques 1.
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
1 Data Structures and Algorithms Queue. 2 The Queue ADT Introduction to the Queue data structure Designing a Queue class using dynamic arrays Linked Queues.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A3 – Basic Data Structures (Stacks)
STACKS & QUEUES II Array Based Approach.
CS505 Data Structures and Algorithms
CC 215 Data Structures Queue ADT
Linked Lists.
Data Structures 7th Week
Basic Data Structures – Continued (Queues)
Stack and Queue APURBO DATTA.
CSCE 3110 Data Structures & Algorithm Analysis
Lectures on data structures and C 3ed CS(CSI33) By, CHANDRASHEKAR A.M.
CSC215 Homework Homework 11 Due date: Dec 19, 2016.
18.5 Linked Queues Like a stack, a queue can be implemented using pointers and nodes Allows dynamic sizing, avoids issue of wrapping indices NULL front.
Queues: Implemented using Arrays
Figure 7.1 Some queue operations. Figure 7.1 Some queue operations.
Circular Queues: Implemented using Arrays
Queue.
Data Structures and Programming Techniques
Data Structures & Programming
Presentation transcript:

Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A4 – Basic Data Structures – Continued (Queues)

2 Basic Data Structures Stacks Queues Lists

3 Overview What is a Queue? Queue Operations. Applications. Linear Implementation. Circular Implementation.

4Append Before FrontRear After FrontRear

5Serve Before FrontRear After Front Rear This comes off the queue

6 Operations Initialize the queue. Append an item to the rear of the queue. Serve an item from the front of the queue. Is the queue empty? Is the queue full? What size is the queue?

7 Applications In operating systems, e.g. printer queues, process queues, etc. Simulation programs. Algorithms.

8 Linear Implementation Front Rear 0 dogfishduckcatfinch

9 Append FrontRear 0 dogfishduckcatfinchsnake

10 Append FrontRear 0 dogfishduckcatfinchsnakeeel

11 Serve FrontRear 0 fishduckcatfinchsnakeeel dog This comes off the queue

12 Serve Front Rear 0 duckcatfinchsnakeeel fish This comes off the queue

13 Append FrontRear 0 duckcatfinchsnakeeeltiger

14 Append FrontRear 0 duckcatfinchsnakeeeltiger ape NO ROOM HERE ROOM HERE

15 Circular Implementation

16 Append Front 0 duckcatfinchsnakeeeltiger ape Rear ape Circular Implementation

17 #define MAXQUEUE 20 struct QueueRec { int count; int front; int rear; float entry[MAXQUEUE]; }; typedef struct QueueRec Queue; Queue: entry: count: front: rear:

18 #ifndef QUEUEH #define QUEUEH #include #define MAXQUEUE 20 struct QueueRec { int count; int front; int rear; float entry[MAXQUEUE]; }; typedef struct QueueRec Queue; void intializeQueue(Queue* queuePtr); bool queueEmpty(const Queue* queuePtr); bool queueFull(const Queue* queuePtr); void append(Queue* queuePtr, float item); float serve(Queue* queuePtr); #endif

#include #include “queue.h” void initializeQueue(Queue* queuePtr) { queuePtr -> count = 0; queuePtr -> front = 0; queuePtr -> rear = MAXQUEUE-1; } rear: entry: Queue: addr of Queue queuePtr: 19 count: 0 front: 0 19

bool queueEmpty(const Queue* queuePtr) { if (queuePtr->count <= 0) { return true; } else { return false; } 20 bool queueFull(Queue* queuePtr) { if (queuePtr->count >= MAXQUEUE) { return true; } else { return false; }

void append(Queue* queuePtr, float item) { if (queueFull(queuePtr)) { fprintf(stderr, “Queue is full\n”); exit(1); } else { queuePtr->rear++; if (queuePtr->rear == MAXQUEUE) { queuePtr->rear = 0; } queuePtr->entry[queuePtr->rear] = item; queuePtr->count++; } 21

float serve(Queue* queuePtr) { float item; if (queueEmpty(queuePtr)) { fprintf(stderr, “Queue is empty\n”); exit(1); } else { item = queuePtr->entry[queuePtr->front]; queuePtr->front++; if (queuePtr->front == MAXQUEUE) { queuePtr->front = 0; } queuePtr->count--; } return item; } 22

23Revision Queue Main Operations Implementation. Revision: Reading Kruse: Chapter 4.1 to 4.2 Deitel & Deitel: Chapter 12.6 Standish: Chapter 7 Langsam: Chapter 4.1 Preparation Next lecture: Lists Kruse 4.5, 4.6, 4.8 Deitel & Deitel (2e) 12.1, 12.2, 12.4