This flashcard is just one of a free flashcard set. See all flashcards!
8
Beschreibe die Funktionen size(), isEmpty() und enqueue(), dequeue mit Exceptions bei einer Queuelänge von N!
Algorithm size()
return (N-f+r) mod N
Algorithm isEmpty()
return (f==r)
Algorithm enqueue(o)
if size() = N − 1 then throw FullQueueException
else Q[r] ← o r ← (r + 1) mod N
Algorithm dequeue()
if isEmpty() then throw EmptyQueueException
else
o ← Q[f]
f ← (f + 1) mod N
return o
return (N-f+r) mod N
Algorithm isEmpty()
return (f==r)
Algorithm enqueue(o)
if size() = N − 1 then throw FullQueueException
else Q[r] ← o r ← (r + 1) mod N
Algorithm dequeue()
if isEmpty() then throw EmptyQueueException
else
o ← Q[f]
f ← (f + 1) mod N
return o