Quee Using Arry Lab 5
Quee Using Arry Lab 5
Faculty of Engineering
Objectives
The purpose of this lab session is to understand the implementation of a queue using an array with its basic
operations.
Introduction
A Queue is an ordered collection of itemns from which items may be deleted at one end (called the front of
the queue) and inserted at the other end (the rear of the queue). Queues remember things in first-in-first-
out (FIFO) order. The basic operations in a queue are: Enqueue- Adds an item to the end of queue.Dequeue
- Removes an item from the front. A queue is implemented using a one dimensional array. FRONT is an
integer value, which contains the array index of the front element of the array. REAR is an integer value,
which contains the array index of the rear element of the array. When an element is deleted from the queue,
the value of HEAD is increased by one, i.e. HEAD = HEAD + 1. When an element is inserted into the queue,
the value of TAIL is increased by one, i.e. TAIL=TAIL+1.
Code:
#include <iostream>
using namespace std;
#define MAX 100
class Queue{
private:
int arr[MAX];//Array to store the queue elements
int front;// Index of thefront element
int rear;// Index of the rear element
public:
//Constructor to initialize the queue
Queue(){
front=-1;
rear=-1;
}
+λ{
int main(){
#define MAX 100
}
};
int main(){
Queue q;
return 0;
}
了
Output:
Output
Queue contents: 10 20 30 40
Queue contents after deletion: 20 30 40