queue code Flashcards

1
Q

enqueue()

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

is full ()

A

FUNCTION is_full(rear)
IF (tail+ 1) == MAX_SIZE THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDFUNCTION

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

is empty()

A

FUNCTION is_empty(front, rear)
IF head = tail THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDFUNCTION

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

dequeue()

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly