queue code Flashcards
enqueue()
FUNCTION enqueue(queue, rear, data)
IF is_full(tail) == True THEN
PRINT (“Queue is full”)
ELSE
Tail = tail + 1
queue[tail] = data
ENDIF
RETURN tail
ENDFUNCTION
is full ()
FUNCTION is_full(rear)
IF (tail+ 1) == MAX_SIZE THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDFUNCTION
is empty()
FUNCTION is_empty(front, rear)
IF head = tail THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDFUNCTION
dequeue()
FUNCTION dequeue(queue, front, rear)
IF is_empty(head, tail) == True THEN
PRINT(“Queue is empty - nothing to dequeue”)
dequeued_item = Null
ELSE
dequeued_item = queue[head]
tail = tail + 1
ENDIF
RETURN (dequeued_item, tail)
ENDFUNCTION