12. Adding and Deleteing from a queue

A queue maintains two pointers

  1. A 'front of queue' pointer.
  2. An 'end of queue' pointer.

a queue

These are used to add and remove nodes from the queue

To add an item to a queue.

  1. Is the queue full?
  2. Case 1: Queue is full
    1. Return an error message to the calling function
    2. End of task
  3. Case 1: Queue is not full
    1. Allocate memory to the new node
    2. Adjust the rear pointer to locate the new node

To remove an item to a queue.

  1. Is the queue empty?
  2. Case 1: Queue is empty
    1. Return an error message to the calling function
    2. End of task
  3. Case 1: Queue is not empty
    1. Mark the memory the node used as free once more
    2. Adjust the rear pointer to locate the previous node
    3. End of task

 

 

Copyright © www.teach-ict.com