Mangalmay Institute of Engineering & Technology 2023
My Stats
EXP gained
7971
Level
6 (Specialist)
Community stats
Discussions
2
0
Know more
294
Total problems solved
258
Easy
34
Moderate
2
Hard
0
Ninja

Current streak:

0 days

Longest streak:

26 days

Less

More

Achievements
3
Ronin
Topics
Arrays
Strings
Discussions
Queue implementation using array
Interview problems

#include <bits/stdc++.h>  class Queue {    int *arr;    int Front;    int back;    int n = 1000;     public:    Queue() {        // Implement the Constructor        arr = new int[n];        Front = -1;        back = -1;    }

/*----------------- Public Functions of Queue -----------------*/

bool isEmpty() {        // Implement the isEmpty() function        if(Front == -1 || Front > back){            return true;        }        return false;    }

void enqueue(int data) {        // Implement the enqueue() function        if(back == n-1){            return;        }        back++;        arr[back] = data;        if(Front == -1){            Front++;        }    }

int dequeue() {        // Implement the dequeue() function        if(Front == -1 || Front > back){            return -1;        }                int ele = arr[Front];        Front++;        return ele;    }

int front() {        // Implement the front() function        if(Front == -1 || Front > back){            return -1;        }        return arr[Front];    } };

Ankit_021
Published On 04-Dec-2022
151 views
0 replies