Your SlideShare is downloading. ×
Queue
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Queue

996
views

Published on


1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total Views
996
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
1
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Q U E U E A lecture by ABDUL GHAFFAR Based on Chapter 3 Of Reference Book #1
  • 2. Reference Books
        • Data Structures and Algorithm Analysis in C
          • By Mark Allen Weiss
            • Published by Addison Wesley
        • Data Structures (Schaum’s Outline Series)
          • By Seymour Lipschutz
            • Published by Mc Graw Hill
  • 3. A QUEUE MODEL
    • Definitions:
      • A QUEUE is a list with the restriction that insertion is done at one end , where as deletion at the other and.for that reason it is called FIFO ( First in first out ) structure.
      • The end where insertion is performed is called the rear .
      • The end where Deletion is performed is called the front .
      • The number of elements in a queue is called the size of the queue
    • Set of operations:
      • Enqueue : Inserts an element at the end (rear) of the list
      • Dequeue : Returns and deletes the element at the start (front) of the list.
    QUEUE Dequeue Enqueue
  • 4. Implementation
      • As Array
        • Define an Array ‘ Queue ’ of sufficient capacity to store Queue elements.
        • Uses a variable i.e rear to remember the position of insertion end.
        • Uses a variable i.e front to remember the position of deletion end.
        • Uses a variable i.e size to remember the size of the array.
        • Write a function Enqueue which takes an element x as argument and performs
          • size = size +1
          • rear = rear +1
          • Queue[rear] = x
        • Write a function Dequeue, which returns the value at front as
          • return Queue[front]
          • front=front+1
          • size=size-1
  • 5. Example: 4 2 R F Size = 2 Initial 4 2 1 F Size = 3 R After Enqueue(1) 4 2 3 1 F Size = 4 R After Enqueue(3) 4 2 3 1 F Size = 3 R After Dequeue r, 2 is returned 4 2 3 1 Size = 2 R F After Dequeue, 4 is returned 4 2 3 1 Size = 1 RF After Dequeue, 1 is returned 4 2 3 1 Size = 0 F R After Dequeue, 3 is returned