A LEVEL COMPUTING
Data Structures
Theory
12. Adding and Deleteing from a queue
A queue maintains two pointers
- A 'front of queue' pointer.
- An 'end of queue' pointer.
These are used to add and remove nodes from the queue
To add an item to a queue.
- Is the queue full?
- Case 1: Queue is full
- Return an error message to the calling function
- End of task
- Case 1: Queue is not full
- Allocate memory to the new node
- Adjust the rear pointer to locate the new node
To remove an item to a queue.
- Is the queue empty?
- Case 1: Queue is empty
- Return an error message to the calling function
- End of task
- Case 1: Queue is not empty
- Mark the memory the node used as free once more
- Adjust the rear pointer to locate the previous node
- End of task
Copyright © www.teach-ict.com