My Stats
EXP gained
2257
Level
5 (Champion)
Community stats
Discussions
0
0
Know more
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
54
Total problems solved
45
Easy
8
Moderate
1
Hard
0
Ninja

Current streak:

0 days

Longest streak:

4 days

Less

More

Achievements
2
Ronin
Topics
Arrays
Discussions
can any one find the error in these code
Interview problems

#include<iostream>

using namespace std;

class circularQueue{

public:

int size;

int * arr;

int front;

int rear;

int isEmpty(){

if(rear==front){

return 1;

}

return 0;

}

int isFull(){

if(((rear+1)%size)==front){

return 1;

}

return 0;

}

void Enqueue(int data){

if(isFull()==1){

cout<<"The Circular Queue is full"<<endl;

}

else{

rear = (rear+1)%size;

arr[rear] = data;

rear++;

cout<<"Enqueue element --> "<<data<<endl;

}

}

void Dequeue(){

if(isEmpty()==1){

cout<<"The Circular Queue is empty"<<endl;

}

else{

front = (front+1)%size;

cout<<"Dequeue element --> "<<arr[front]<<endl;

front++;

}

}

};

int main(){

circularQueue * c = new circularQueue();

c->size = 10;

c->arr = new int[c->size];

c->front=0;

c->rear=0;

c->Enqueue(10);

c->Enqueue(20);

c->Enqueue(30);

c->Enqueue(40);

c->Enqueue(50);

c->Enqueue(60);

c->Enqueue(70);

c->Enqueue(80);

c->Enqueue(90);

c->Enqueue(100);

c->Dequeue();

}

Published On 12-Aug-2023
28 views
0 replies