Data Structures( 数据结构 ) Course 5:Queue. Vocabulary. queue 队列 enqueue 进队 dequeue 出队 queue front 队头 queue rear 队尾 Queuing theory 排队论. 5.1 Queue Operations.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Data Structures(数据结构)Course 5:Queue
queue 队列
enqueue 进队
dequeue 出队
queue front 队头
queue rear 队尾
Queuing theory排队论
Remove
(dequeue)
(Enqueue)
front
rear
A computer queue
grape
data
Enqueue
plum
kiwi
grape
plum
kiwi
front
rear
front
rear
Queue
Queue
Operation
plum
data
Dequeue
grape
kiwi
plum
kiwi
grape
front
rear
front
rear
Operation
Queue
Queue
plum
data
Queue
front
plum
kiwi
grape
plum
kiwi
grape
front
rear
front
rear
Operation
Queue
Queue
grape
data
Queue
rear
plum
kiwi
grape
plum
kiwi
grape
front
rear
front
rear
Operation
Queue
Queue
plum
kiwi
grape
fig
plum
kiwi
grape
fig
front
rear
Conceptual queue
rear
front
4
front
rear
Physical queue
data
next
count
front
rear
Head structure
Node structure
No queue
count
count
front
rear
front
rear
0
?
?
?
Before
After
count
count
front
rear
front
rear
0
1
data
data
next
next
plum
plum
newPtr
newPtr
After
Before
Insert into empty queue
count
front
rear
newPtr
1
data
data
next
next
plum
kiwi
count
front
rear
newPtr
2
data
data
next
next
plum
kiwi
There are four ways to test if the queue is null 1.Front null
2.Rear null
3.Count 0
4.Emptyqueue
Before
After
Insert into queue with data
count
front
rear
1
data
next
plum
Dequeue:
1. Ensure that the queue contains data.
2. Pass the data back through the parameter list and then set the front pointer to the next item in the queue.
3. If the queue is now empty, set the rear pointer to null.
count
front
rear
0
(recycled)
deleteLoc
Before
After
Delete only item in queue
count
front
rear
2
data
data
next
next
plum
kiwi
Before
count
front
rear
1
data
data
next
next
plum
kiwi
(recycled)
After
deleteLoc
Empty Queue: it returns true if the queue is empty and false if the queue contains data.
Full Queue: By allocating a node and then releasing the memory we can determine whether there is room for at least one more node.
Queue Count: it returns the number of elements currently in the queue by returning the count found in the queue head node.
Destroy Queue: it deletes all data in the queue and recycles their memory.
Queue
Server
Queue
time
Service
time
Response
time
A queuing theory model
count
front
rear
2
custNum
arriveTime
next
startTime
svcTime
arriveTime
custNum
totWaitTime
maxQueueSize
totSvcTime
numCust
head
node
custStatus
simStats
Figure 5-13 queue data structures
Simulator
Create
queue
New
customer
Server
free
Service
complete
stats
Figure 5-14 design for queue simulation
custStatus
custNum <integer>
arriveTime <integer>
startTime <integer>
svcTime <integer>
end custstatus
simStats
numCust <integer>
totSvcTime <integer>
totWaitTime <integer>
maxQueueSize <integer>
end simstats
Algorithm taffySimulation
Data Structures
data
number <integer>
arrivalTime <integer>
end data
head
front <node pointer>
count <integer>
rear <node pointer>
end head
node
custData <data>
next <node pointer>
end node
Algorithm 5-9 queue simulation: driver
Service complete
Print stats
then categorize them into four different groups:
Group1: less than 10
Group2: between 10 and 19
Group3: between 20 and 29
Group4: 30 and greater
3 22 12 6 10 34 65 29 9 30 81 4 5 19 20 57 44 99
3 6 9 4 5 12 10 19 22 29 20 34 65 30 81 57 44 99
Algorithm categorize
End categorize
PushStack(S,3)
PushStack(S,12)
Enqueue(Q,5)
Enqueue(Q,8)
PopStack(S,x)
pushStack(S,2)
Enqueue(Q,x)
Dequeue(Q,y)
PushStack(S,x)
PushStack(S,y)
Q1=createQueue
Q2=createQueue
Loop (not end of file)
read number
enqueue(Q1,number)
enqueue(Q2,number)
loop (Not empty Q1)
dequeue(Q1,x)
enqueue(Q2,x)
End loop
End loop
The data are 5,7,12,4,0,4,6