Download presentation
Presentation is loading. Please wait.
1
S KIRAN PGT(COMP) KV CLRI
QUEUES 12/12/2019 S KIRAN PGT(COMP) KV CLRI
2
S KIRAN PGT(COMP) KV CLRI
QUEUE What is a Queue? A Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO) . 12/12/2019 S KIRAN PGT(COMP) KV CLRI
3
S KIRAN PGT(COMP) KV CLRI
REAL LIFE EXAMPLES Railway ticket counter Cinema ticket counter Application form counters Electricity bill payment counters 12/12/2019 S KIRAN PGT(COMP) KV CLRI
4
S KIRAN PGT(COMP) KV CLRI
APPLICATIONS OF QUEUE When a resource is shared among multiple consumers. Examples include 1.CPU scheduling 2. Printing (shared resource) 12/12/2019 S KIRAN PGT(COMP) KV CLRI
5
S KIRAN PGT(COMP) KV CLRI
OPERATIONS ON QUEUE INSERT, the process of adding an element to the queue. If the queue is full, then it is said to be an Overflow condition. 12/12/2019 S KIRAN PGT(COMP) KV CLRI
6
S KIRAN PGT(COMP) KV CLRI
INSERT OPERATION Rear Rear Rear Rear Rear front 12/12/2019 S KIRAN PGT(COMP) KV CLRI
7
S KIRAN PGT(COMP) KV CLRI
OPERATIONS ON QUEUE DELETE, the process of removing the first element that was added. If the queue is empty, then it is said to be an Underflow condition. 12/12/2019 S KIRAN PGT(COMP) KV CLRI
8
S KIRAN PGT(COMP) KV CLRI
DELETE OPERATION Rear 12/12/2019 S KIRAN PGT(COMP) KV CLRI
9
S KIRAN PGT(COMP) KV CLRI
IMPLEMENATION QUEUE can be implemented in two ways 1. STATIC (Arrays) 2. DYNAMIC (Linked List) 12/12/2019 S KIRAN PGT(COMP) KV CLRI
10
Testing Previous Knowledge
What is self referential structure? It is a structure definition which includes at least one member that is a pointer to the structure of its own kind. What is linked list? A linked list is a linear collection of data elements, in which linear order is not given by their physical placement in memory. Each pointing to the next node by means of a pointer. 12/12/2019 S KIRAN PGT(COMP) KV CLRI
11
S KIRAN PGT(COMP) KV CLRI
DYNAMIC QUEUES For Dynamic Implementation we require two pointers, front and rear. The front points the first NODE of queue and rear points to last NODE. 12/12/2019 S KIRAN PGT(COMP) KV CLRI
12
DYNAMIC QUEUE(INSERT)
class QUEUE { Node *rear,*front; public: queue() rear=NULL; front=NULL; } void INSERT(); void DELET(); }; struct Node { int age; Node *Link; }; 12/12/2019 S KIRAN PGT(COMP) KV CLRI
13
S KIRAN PGT(COMP) KV CLRI
void queue::INSERT() { Node *nptr = new Node; if(!nptr) cout<<“ Over Flow”; return; } cout<<"Enter the age "; cin>>nptr->age; nptr->Link=NULL; if(rear==NULL) front=rear=nptr; else rear->Link=nptr; rear=nptr; front NULL rear NULL nptr 1000 1000 1000 2000 F NULL 1000 R R 23 2000 23 NULL 30 NULL 1000 2000 12/12/2019 S KIRAN PGT(COMP) KV CLRI
14
DYNAMIC QUEUE (DELETE)
front 1000 rear 2000 ptr 1000 void queue::DELET() { node *ptr = front; if(front==NULL) cout<<"Underflow"; else front=front->Link; delete ptr; if(front==NULL) rear=NULL; } 2000 NULL NULL 2000 1000 2000 NULL R 23 2000 1000 30 NULL 2000 12/12/2019 S KIRAN PGT(COMP) KV CLRI
15
S KIRAN PGT(COMP) KV CLRI
BOARD EVALUATION 12/12/2019 S KIRAN PGT(COMP) KV CLRI
16
S KIRAN PGT(COMP) KV CLRI
void queue::INSERT() { Node *nptr = new Node; // 1 MARK if(!nptr) cout<<“ Over Flow”; return; } cout<<"Enter the age "; cin>>nptr->age; // 1 MARK nptr->Link=NULL; if(rear==NULL) // ½ MARK front=rear=nptr; // ½ MARK else rear->Link=nptr; // ½ MARK rear=nptr; // ½ MARK 12/12/2019 S KIRAN PGT(COMP) KV CLRI
17
S KIRAN PGT(COMP) KV CLRI
THANK YOU 12/12/2019 S KIRAN PGT(COMP) KV CLRI
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.