Let Q[N] be an array implementation of the queue, of size N and type T.
Then ‘front’ is a variable that point to the front element of the queue and
‘rear’ is a variable that point to the last element of the queue. Then queue as
an ADT is as:
·
MakeEmpty(Q): Make an empty queue Q which sets rear=-1 and front=0.
·
IsEmpty(Q): Return 1(TRUE) if the queue Q is empty(rear<front), otherwise
0(FALSE).
·
IsFull(Q):Return 1(TRUE) if the queue Q is Full(rear==N-1), otherwise 0(FALSE).
·
enqueue(Q, item): Add an element ‘item’ at the ‘rear’ of the queue Q if it is not full.
·
dequeue(Q): Remove an element from the ‘front’ of the queue Q if it is not empty.
·
traverse(Q): Display all the elements of the Queue Q if Q is not empty.
·
front(Q): Display the front element of the queue Q if it is not empty.
No comments:
Post a Comment