Rear Operation in Queue Data Structure
This operation returns the element at the rear end without removing it.
int rear(queue<int>& myQueue)
{
queue<int> tempQueue = myQueue;
while (tempQueue.size() > 1) {
tempQueue.pop();
}
return tempQueue.front();
}
int rear(struct Queue* front)
{
if (front == NULL) {
printf("Queue is empty.\n");
return -1;
}
while (front->next != NULL) {
front = front->next;
}
return front->data;
}
public static int rear(Queue<Integer> myQueue)
{
if (myQueue.isEmpty()) {
System.out.println("Queue is empty.");
return -1;
}
int rearElement = -1;
while (!myQueue.isEmpty()) {
rearElement = myQueue.poll();
}
return rearElement;
}
def rear(queue):
if queue.empty():
print("Queue is empty.")
return None
rear_element = None
while not queue.empty():
rear_element = queue.get()
return rear_element
static int Rear(Queue<int> myQueue)
{
if (myQueue.Count == 0) {
Console.WriteLine("Queue is empty.");
return -1;
}
int rearElement = -1;
while (myQueue.Count > 0) {
rearElement = myQueue.Dequeue();
}
return rearElement;
}
function rear(queue) {
if (queue.length === 0) {
console.log("Queue is empty.");
return -1;
}
let rearElement = -1;
while (queue.length > 0) {
rearElement = queue.shift();
}
return rearElement;
}
Introduction to Queue Data Structure
Queue Data Structure is a linear data structure that follows FIFO (First In First Out) Principle, so the first element inserted is the first to be popped out. In this article, we will cover all the basics of Queue, Operations on Queue, its implementation, advantages, disadvantages which will help you solve all the problems based on Queue.
Table of Content
- What is Queue Data Structure?
- Representation of Queue Data Structure:
- Types of Queue Data Structure
- Basic Operations in Queue Data Structure
- 1. Enqueue Operation in Queue Data Structure
- 2. Dequeue Operation in Queue Data Structure
- 3. Front Operation in Queue Data Structure
- 4. Rear Operation in Queue Data Structure
- 5. isEmpty Operation in Queue Data Structure
- 6. isFull Operation in Queue Structure
- Implementation of Queue Data Structure
- Complexity Analysis of Operations on Queue Data Structure
- Applications of Queue Data Structure
- Advantages of Queue Data Structure
- Disadvantages of Queue Data Structure
- FAQs (Frequently asked questions) on Queue Data Structure