Queue ADT and operations
Queue ADT and Operations A queue (also known as a queue data structure or FIFO data structure) is a linear data structure that follows the First-In, First-O...
Queue ADT and Operations A queue (also known as a queue data structure or FIFO data structure) is a linear data structure that follows the First-In, First-O...
Queue ADT and Operations
A queue (also known as a queue data structure or FIFO data structure) is a linear data structure that follows the First-In, First-Out (FIFO) principle. This means that the first element added to the queue is the first one to be retrieved, and elements are added to the rear of the queue in the order in which they are inserted.
Operations on a Queue:
Enqueue (insert element at the rear): The new element is added to the rear of the queue.
Dequeue (extract element from the front): The first element in the queue is removed and returned.
Peek (view the front element without removing it): Returns but does not remove the front element.
IsEmpty(): Checks if the queue is empty.
Full(): Checks if the queue is full.
Examples:
Enqueue: Enqueue(queue, 5)
Dequeue: Dequeue(queue)
Peek: Peek(queue)
IsEmpty: IsEmpty(queue)
Full: IsFull(queue)
Applications of Queues:
Job scheduling: Queues are often used to manage the order in which tasks are executed.
Message passing: Queues can be used to pass messages between different threads or processes.
Logging: Queues can be used to store and process logs in a chronological order.
Stacks: Stacks are a specific type of queue that follows the LIFO (Last-In, First-Out) principle