Basic Data Structures – Continued (Queues)

Slides:



Advertisements
Similar presentations
CSCE 3110 Data Structures & Algorithm Analysis
Advertisements

Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
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.
1 Queues – Chapter 3 A queue is a data structure in which all additions are made at one end called the rear of the queue and all deletions are made from.
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.
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.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
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)
CSE1303 Part A Data Structures and Algorithms Lecture A7 – Nodes and Linked Structures.
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 A4 – Basic Data Structures – Continued (Queues)
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.
CSE1303 Part A Data Structures and Algorithms Lecture A9 – Linked Lists.
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.
1 Queues (Walls & Mirrors - Chapter 7). 2 Overview The ADT Queue Linked-List Implementation of a Queue Array Implementation of a Queue.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A5 – Basic Data Structures – Continued (Lists)
1 MT258 Computer Programming and Problem Solving Unit 9.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 2b. Simple Containers: The Queue.
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.
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.
Queues Manolis Koubarakis Data Structures and Programming Techniques 1.
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.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 2b. Simple Containers: The Queue.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A3 – Basic Data Structures (Stacks)
STACKS & QUEUES II Array Based Approach.
CSCE 210 Data Structures and Algorithms
CS505 Data Structures and Algorithms
CC 215 Data Structures Queue ADT
CSCE 3110 Data Structures & Algorithm Analysis
Linked Lists.
Data Structures 7th Week
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.
CSCI2100 Data Structures Tutorial 7
Queues.
Queues 11/16/2018 4:18 AM Queues 11/16/2018 4:18 AM Queues.
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.
Pointers & Dynamic Data Structures
Circular Queues: Implemented using Arrays
Queue.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Data Structures and Programming Techniques
Data Structures & Programming
Presentation transcript:

Basic Data Structures – Continued (Queues)

Basic Data Structures Stacks Queues Lists

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

Append Before Front Rear After Front Rear

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

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?

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

Linear Implementation 1 2 3 4 5 6 7 Front Rear

Append 1 2 3 4 5 6 7 Front Rear

Append 1 2 3 4 5 6 7 Front Rear

Serve 1 2 3 4 5 6 7 Front Rear This comes off the queue

Serve 1 2 3 4 5 6 7 Front Rear This comes off the queue

Append 1 2 3 4 5 6 7 Front Rear

Append 1 2 3 4 5 6 7 Front Rear NO ROOM HERE

Append 1 2 3 4 5 6 7 Front Rear ROOM HERE

Circular Implementation 7 6 1 5 2 4 3

Circular Implementation 1 2 3 4 5 6 7 Front Rear

Append 1 2 3 4 5 6 7 Rear Front

float entry[MAXQUEUE]; }; typedef struct QueueRec Queue; #ifndef QUEUEH #define QUEUEH #include <stdbool.h> #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

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

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

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

bool queueFull(Queue* queuePtr) { if (queuePtr->count >= MAXQUEUE) return true; } else return false; 23

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++; 24

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; 25

Revision Queue Main Operations Implementation.

Next Lists