Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Queues.

Slides:



Advertisements
Similar presentations
Data Structure HKOI training /4/2010 So Pak Yeung.
Advertisements

Ceng-112 Data Structures I Chapter 5 Queues.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
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.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Stacks.
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.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Data Structures - Queues
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Trees.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Data Structures Systems Programming. 22 Data Structures  Queues –Queuing System Models –Queue Data Structures –A Queue Example  Trees –Binary Trees.
CS 1031 Linked Lists Definition of Linked Lists Examples of Linked Lists Operations on Linked Lists Linked List as a Class Linked Lists as Implementations.
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’
Data structures Abstract data types Java classes for Data structures and ADTs.
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.
Implementation of QUEUE For more notes and topics visit: eITnotes.com.
Programming Practice 3 - Dynamic Data Structure
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Stack.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
Data Structures - Prabir Sarkar. AGENDA Stack Queue Linked List Trees Graphs Searching and Sorting Algorithm.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Queue.
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.
 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.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
Review Array Array Elements Accessing array elements
Cpt S 122 – Data Structures Abstract Data Types
Data Structure By Amee Trivedi.
Queues Chapter 4.
Chapter 12 – Data Structures
5.13 Recursion Recursive functions Functions that call themselves
CC 215 Data Structures Queue ADT
12 C Data Structures.
12 C Data Structures.
Chapter 22 Custom Generic Data Structures
Chapter 15 Lists Objectives
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Queues Queues Queues.
Queues Chapter 4.
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Chapter 15 Lists Objectives
Queues.
DATA STRUCTURE QUEUE.
Review & Lab assignments
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
Instructor: Dr. Michael Geiger Spring 2019 Lecture 29: Linked queues
CSCS-200 Data Structure and Algorithms
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Queues

Topics Queues  enqueue, dequeue, printqueue Queues Applications

Queues Queue is another common data structure. A queue is similar to a checkout line in a grocery store—the first person in line is serviced first, and other customers enter the line only at the end and wait to be serviced. Queue nodes are removed only from the head of the queue and are inserted only at the tail of the queue. For this reason, a queue is referred to as a first-in, first-out (FIFO) data structure. The insert and remove operations are known as enqueue and dequeue, respectively.

Queues (Cont.) Queues have many applications in computer systems. For computers that have only a single processor, only one user at a time may be serviced. Entries for the other users are placed in a queue. Each entry gradually advances to the front of the queue as users receive service. The entry at the front of the queue is the next to receive service.

Queues (Cont.) Queues are also used to support print spooling. A multiuser environment may have only a single printer. Many users may be generating outputs to be printed. If the printer is busy, other outputs may still be generated. These are spooled to disk where they wait in a queue until the printer becomes available.

Queues (Cont.) Information packets also wait in queues in computer networks. Each time a packet arrives at a network node, it must be routed to the next node on the network along the path to its final destination. The routing node routes one packet at a time, so additional packets are enqueued until the router can route them.

Queue Manipulations The program provides several options:  insert a node in the queue (function enqueue ),  remove a node from the queue (function dequeue ) and  terminate the program. Note the pointers to the head of the queue and the tail of the queue. enqueue dequeue

Queues Example

Function enqueue

Function enqueue receives three arguments from main :  the address of the pointer to the head of the queue,  the address of the pointer to the tail of the queue and  the value to be inserted in the queue.

Function enqueue (Cont.) The function consists of three steps:  To create a new node: Call malloc, assign the allocated memory location to newPtr, assign the value to be inserted in the queue to newPtr->data and assign NULL to newPtr->nextPtr.  If the queue is empty, assign newPtr to *headPtr, because the new node will be both the head and tail of the queue; otherwise, assign pointer newPtr to (*tailPtr)->nextPtr, because the new node will be placed after the previous tail node.  Assign newPtr to *tailPtr, because the new node is the queue’s tail..

Operation enqueue The dotted arrows in part (b) illustrate Steps 2 and 3 of function enqueue that enable a new node to be added to the end of a queue that is not empty.

Function dequeue

Function dequeue receives two arguments  the address of the pointer to the head of the queue  the address of the pointer to the tail of the queue as arguments  removes the first node from the queue.

Function dequeue The dequeue operation consists of six steps:  Assign (*headPtr)->data to value to save the data.  Assign *headPtr to tempPtr, which will be used to free the unneeded memory.  Assign (*headPtr)->nextPtr to *headPtr so that *headPtr now points to the new first node in the queue.  If *headPtr is NULL, assign NULL to *tailPtr because the queue is now empty.  Free the memory pointed to by tempPtr.  Return value to the caller.

Operation dequeue Part (b) shows tempPtr pointing to the dequeued node, and headPtr pointing to the new first node of the queue.  Function free is used to reclaim the memory pointed to by tempPtr.

Function printQueue

Output

Conclusions What are the differences between a linked list and a stack? What are the differences between a stack and a queue?

Conclusions What are the differences between a linked list and a stack?  Possible to insert and remove a node from anywhere in a linked list.  Nodes in a stack may be inserted only at the top of the stack and removed only from the top of the stack. What are the differences between a stack and a queue?  A queue has pointers to both its head and tail so that nodes may be inserted at the tail and deleted from the head.  A stack has a single pointer to the top of the stack where both insertion and deletion of nodes is performed.

Conclusions Implementing linked list, stack & queue functions