Today, we will talk about another linear data structure, a Queue.
It is a data structure thay basically acts like a real life queue. It works on FIFO(First in First out) principle. It means that the element that gets added to the queue first gets removed the first, it's like first come first serve basis.In a queue, the operations take effect at rear and front end of the list. Enque adds the element to the back of the queue and Dequeue removes the element from the front of the queue. Queue is a very essential data structure and also form the basis for some advanced data structures.
Applications of a queue-
- CPU procces scheduling
- Real life simulations
The methods associated with a queue are -
- Enque():
- Adds an element to the back of the queue
- Deque():
- Removes an element from the front of the queue
- isEmpty():
- Returns wether the queue is empty or not
- size():
- Returns the size of the queue
Here is the implementation of the Queue data structure, in this implementation we use a list to simulate a queue
Comments
Post a Comment