data structures using ‘c’ · data structures using ‘c ... queue • ordered collection of...
TRANSCRIPT
![Page 1: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/1.jpg)
DATA STRUCTURES USING ‘C’
![Page 2: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/2.jpg)
Free Powerpoint Templates Page 2
LectureLecture--1515
![Page 3: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/3.jpg)
Free Powerpoint Templates Page 3Free Powerpoint Templates
QUEUE
![Page 4: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/4.jpg)
Queue
• Ordered collection of homogeneous elements
• Non-primitive linear data structure.
• A new element is added at one end calledrear end and the existing elements aredeleted from the other end called front end.
• This mechanism is called First-In-First-Out(FIFO).
• Total no of elements in queue= rear – front +1
![Page 5: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/5.jpg)
Fig: Models of a Queue
![Page 6: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/6.jpg)
Free Powerpoint Templates Page 6
Operations On A QueueOperations On A Queue
1.To insert an element inqueue
2.Delete an element fromqueue
![Page 7: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/7.jpg)
Free Powerpoint Templates Page 7
The Queue OperationThe Queue Operation
Placing an item in a queue is called “insertion or enqueue”, which is done at the end of the queue called “rear”.
FrontRear
![Page 8: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/8.jpg)
Free Powerpoint Templates Page 8
The Queue OperationThe Queue Operation
Removing an item from a queue iscalled “deletion or dequeue”, whichis done at the other end of the queue called “front”.
FrontRear
![Page 9: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/9.jpg)
Free Powerpoint Templates Page 9
Algorithm QINSERT (ITEM)Algorithm QINSERT (ITEM)
1.If (rear = maxsize-1 )
print (“queue overflow”) and return
2.Else
rear = rear + 1
Queue [rear] = item
![Page 10: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/10.jpg)
Free Powerpoint Templates Page 10
Algorithm QDELETE ()Algorithm QDELETE ()1.If (front =rear)
print “queue empty” and return
2. Else
Front = front + 1
item = queue [front];
Return item
![Page 11: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/11.jpg)
Free Powerpoint Templates Page 11
Queue ApplicationsQueue Applications
Real life examplesWaiting in lineWaiting on hold for tech support
Applications related to Computer ScienceRound robin schedulingJob scheduling (FIFO Scheduling)Key board buffer
![Page 12: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/12.jpg)
Free Powerpoint Templates Page 12
3 states of the queue3 states of the queue1.Queue is empty
FRONT=REAR2.Queue is full
REAR=N3.Queue contains element >=1
FRONT<REARNO. OF ELEMENT=REAR-FRONT+1
![Page 13: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/13.jpg)
Free Powerpoint Templates Page 13
Representation Of QueuesRepresentation Of Queues1.Using an array2.Using linked list
![Page 14: DATA STRUCTURES USING ‘C’ · DATA STRUCTURES USING ‘C ... Queue • Ordered collection of homogeneous elements • Non-primitive linear data structure. • A new element is](https://reader033.vdocument.in/reader033/viewer/2022042003/5e6e7c5efcabb777f2533ac2/html5/thumbnails/14.jpg)
Free Powerpoint Templates Page 14