Topic 3 Basic Data Structures continued CSE1303 Part A Data Structures and Algorithms.

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 Stack and Queue. 2 Stack In Out ABCCB Data structure with Last-In First-Out (LIFO) behavior.
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.
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.
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.
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.
Lecture 11 Sept 26, 2011 Goals convert from infix to postfix.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 18: Stacks and.
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)
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.
1 Queues. 2 Queue Which of the following cases use similar structures? Cars lined up at a tollgate Cars on a 4-lane highway Customers at supermarket check-out.
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.
Queue 09/10/081. Queue (Linear Queue) It is a linear data structure consisting of list of items. In queue, data elements are added at one end, called.
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.
CSCE 210 Data Structures and Algorithms
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.
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.
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 & Programming
Presentation transcript:

Topic 3 Basic Data Structures continued CSE1303 Part A Data Structures and Algorithms

Basic Data Structures Stacks Queues Lists

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

Append Before FrontRear After FrontRear

Serve Before FrontRear 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 Front Rear

Append FrontRear

Append FrontRear

Serve FrontRear This comes off the queue

Serve Front Rear This comes off the queue

Append FrontRear

Append FrontRear NO ROOM HERE

Append FrontRear ROOM HERE

Circular Implementation

FrontRear

Append FrontRear

#ifndef QUEUE.H #define QUEUE.H #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

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

#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

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

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

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

Revision Queue Main Operations Implementation. Preparation Kruse 4.5, 4.6, 4.8 Deitel & Deitel (2e) 12.1, 12.2, 12.4