IMPLEMENTATION OF QUEUE
IMPLEMENTATION OF QUEUE USING ARRAYS:
There are 3 basic operations that can be performed on a queue:
- enqueue()
- dequeue()
- display()
Algorithm for enqueue() operation:
step1: start
step2: check whether the queue is full or not (rear==size-1). If it is true , display enqueue() operation not possible.
step3: check whether the queue is empty(front==rear==-1 or front>rear).
If it is true that both front and rear pointers have been incremented by 1, and the element pointed by rear is stored, then it is true.
i.e. front++;
rear++;
queue[rear]=value;
step4: check whether the queue is not empty and not full, then increment the rear point and store the value points by rear in the queue.
i.e. rear++;
queue[rear]=value;
step5: stop.
Algorithm for dequeue() operation:
step1: start
step2: check whether the queue is empty or not(front==rear==-1 or front>rear). If it is true, dequeue()
operation is not possible.
step3: check whether the queue is full or not. If it is full, dequeue operation is performed
i.e. delete element=queue[front]
display delete element
front++;
step4: stop.
Algorithm for display() operation:
step1: start
step2: check whether the queue is empty or not(front==rear==-1).If it is true, queue is empty so display operation is not possible.
step3: If the queue is not empty (front==rear!==-1) , then we perform display operation.




Comments
Post a Comment