What is Queue?
A queue is defined as a linear data structure that is open at both ends and the operations are performed in First In First Out (FIFO) order.
We define a queue to be a list in which all additions to the list are made at one end, and all deletions from the list are made at the other end. The element which is first pushed into the order, the operation is first performed on that.
FIFO Principle of Queue:
- A Queue is like a line waiting to purchase tickets, where the first person in line is the first person served. (i.e. First come first serve).
- Position of the entry in a queue ready to be served, that is, the first entry that will be removed from the queue, is called the front of the queue(sometimes, head of the queue), similarly, the position of the last entry in the queue, that is, the one most recently added, is called the rear (or the tail) of the queue. See the below figure.
Characteristics of Queue:
- Queue can handle multiple data.
- We can access both ends.
- They are fast and flexible.
Like stacks, Queues can also be represented in an array: In this representation, the Queue is implemented using the array. Variables used in this case are
- Queue: the name of the array storing queue elements.
- Front: the index where the first element is stored in the array representing the queue.
- Rear: the index where the last element is stored in an array representing the queue.
- Introduction to Queue in Data Structures and Algorithms
- Implementations of Queue Data Structure
- https://www.geeksforgeeks.org/applications-of-queue-data-structure/“>Applications, Advantages and Disadvantages of Queue
- Priority Queue
- Applications of Priority Queue
- Circular Queue
- Queue Interface In Java
- Queue In Python
- Queue In C#
- Implement Queue using Stacks
- LRU Cache Implementation
- Implement Stack using Queues
- Queue | Set 2 (Linked List Implementation)
- How to efficiently implement k Queues in a single array?
- Implement a stack using single queue
- Implementation of Deque using circular array
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Implement Stack and Queue using Deque
- Priority Queue using Linked List
- Priority Queue using doubly linked list
- Implementation of Deque using doubly linked list
- Check if a queue can be sorted into another queue using a stack
- Breadth First Traversal or BFS for a Graph
- Level Order Tree Traversal
- Reverse a path in BST using queue
- Construct Complete Binary Tree from its Linked List Representation
- Program for Page Replacement Algorithms | Set 2 (FIFO)
- Check whether a given Binary Tree is Complete or not | Set 1 (Iterative Solution)
- Number of siblings of a given Node in n-ary Tree
- ZigZag Tree Traversal
- FIFO (First-In-First-Out) approach in Programming
- FIFO vs LIFO approach in Programming
- LIFO (Last-In-First-Out) approach in Programming
- Reversing a Queue
- Reversing a queue using recursion
- Reversing the first K elements of a Queue
- Interleave the first half of the queue with second half
- Sorting a Queue without extra space
- Level order traversal in spiral form
- Sliding Window Maximum (Maximum of all subarrays of size k)
- Find the largest multiple of 3 | Set 1 (Using Queue)
- Find the first circular tour that visits all petrol pumps
- Smallest multiple of a given number made of digits 0 and 9 only
- Iterative Method to find Height of Binary Tree
- Implement PriorityQueue through Comparator in Java
- An Interesting Method to Generate Binary Numbers from 1 to n
- Minimum time required to rot all oranges
- Find maximum level sum in Binary Tree
- Sum of minimum and maximum elements of all subarrays of size k.
- Distance of nearest cell having 1 in a binary matrix
- Level order traversal line by line | Set 2 (Using Two Queues)
- First negative integer in every window of size k
- Minimum sum of squares of character counts in a given string after removing k characters
- Queue based approach for first non-repeating character in a stream
- Averages of Levels in Binary Tree
- Stack Permutations (Check if an array is stack permutation of other)
- Check if all levels of two trees are anagrams or not
- Check mirror in n-ary tree
- Check if X can give change to every person in the Queue
Prepare for a job interview with confidence and clarity, Here you’ll get prepared for each and every subject & skill relevant to the interview whether it be core CS subjects, programming language, reasoning & aptitude, resume building, etc. at budget-friendly prices with GeeksforGeeks Complete Interview Preparation Course.
Enrol today to learn data structures, Get best-in-industry real-time GFG Live Courses to upskill yourself and get into your dream company. You can attend these live classes from any geographical region and here you can ask your doubts to the instructor just like an offline classroom program. Do check out these valuable Live Courses by GeeksforGeeks – System Design Live, Competitive Programming Live, and more!
Language Foundation Courses[C Programming / C++ / JAVA / Python ]
Each language is designed to get you right into hands-on practice by offering Language Foundation Courses. Learn any programming language from scratch and understand all its fundamental concepts for a strong programming foundation in the easiest possible manner at best price possible with help of GeeksforGeeks Language Foundation Courses – C Programming | Java Foundation | Python Foundation | C++ Foundation.