Operations on Queue


Operations on Queue


BASIC OPERATIONS:

The most basic queue operations in the data structure are the following

  • enqueue() - Adds an element at the beginning of the queue. If the queue is full, then it is an overflow.
  • dequeue() - Deletes an element at the end of the queue. If the queue is empty, then it is an underflow.

enqueue() 

    1. Check if the queue is full.
    2. If the queue is full, then print "Queue overflow".
    3. Else increment REAR by 1.
    4. Assign QUEUE [ REAR ] = ELEMENT.

dequeue()

    1. Check if the queue is empty.
    2. If the queue is empty, the print "Queue underflow".
    3. Copy the element at the front of the queue to some temporary variable, TEMP = QUEUE[ FRONT ].
    4. Increment FRONT by 1. 
    5. Print temp and delete it.

Post a Comment

0 Comments