Data Structures Chapter 7 Queue 1 Out Line


















- Slides: 18
Data Structures Chapter 7: Queue 1
Out Line What is Queue data structure? En Queue Operation De Queue Operation Clear the Queue Print all the data of Queue Search about data Types of Queue 2
What is Queue data structure? Queues are used to prioritize operating system processes and to simulate events in the real world, such as teller lines at banks and the operation of elevators in buildings. A queue is a data structure where data enters at the rear of list and is removed from the front of the list. Queues are an example of a first- in, first-out (FIFO) data structure. Front Rear head Hussam Ahmed Ali 3 Mohamed Ghadeer
Queue Operations The two primary operations involving queues are adding a new item to the queue and removing an item from the queue. The operation for adding a new item is called Enqueue, and the operation for removing an item from a queue is called Dequeue. The other primary operation (the Peek method) to perform on a queue is viewing the beginning item. 4
What is Queue data structure? 5
Element of Queue Exactly as linked list rear front 1 7 5 2 Front Rear 6
En. Queue Operation Front Ali Rear Mohame d Front Ali 2 Ahmed 1 Ghadeer Rear Mohame d Ghadeer New item Ahmed 7
En. Queue Operation Create new object If rear points to null rear= New. Item Front = New. Item. next = null Else New. Item. next = rear= New. Item size++ index++ 8
De. Queue Operation Front Rear 1 Mohame d Ali Front Ali Rear Mohame d Ghadeer Ahmed 9
De. Queue Operation If front points to null print (the queue is empty) Else for (current = Rear, current. next != Front, current = current. next); Front = current; index--; size--; 10
Peek Operation The retrieved element should be element of the Front of the list. Front. name Front. ID Front. data … 11
Peek Operation If Front points to null print (the queue is empty) Else return top 12
Clear the Queue The clearing of Queue means removing all the elements by set the Front and Rear point to null. 2 1 Front 2 Rear X Ali X 1 Mohame d Ghadeer 13
Clear the Queue If Front points to null print (the stack is empty) Else Rear = null; Front = null; index = -1; size = 0; 14
Print all data of Queue The Print of all elements' data of the Queue means that we have to create a new pointer points every time to the next element. Front Rear 4 3 Ali Mohame d 2 Ghadeer 1 Ahmed 15
Search about data HW 12. 2 Depending on your understanding of the print. All() operation, write a find method which search about a specific data. HW 12. 3 Depending on your understanding of the print. All() operation, write a sort method which sorts the elements of the queue based on the name field. 16
Types of Queue 1 -linear: Which as we have seen he added elements through the rear and pulled through the front. 2 -physical: 3 - circular: This type has the same principle of the linear. But when he filled the rear matrix Due Aocher element 0, and so we can get into the number that we want of numbers but of course when re-0 and start entering data it Values will be placed somewhere values that were present and this type is the best type of queue In the form of matrices
The end. Questions 18