Saturday, September 20, 2025

QUEUE

#include <iostream>
 using namespace std;
 #define MAX 100
 class QUEUE{
int front;
int rear;
int arr[MAX];
public:
QUEUE(){
    front=rear=-1;
}
bool isEmpty(){
    return (front==-1 && rear==-1);
}
bool isFull(){
    return rear==MAX-1;
}
void enqueue(int value){
    if(isFull()){
        cout<<" queue overflow "<<endl;
        return;
    }
   if(isEmpty()){
    front=rear=0;
   }
   else{
    rear++;
   }
arr[rear]=value;
   cout<<arr[rear]<<endl;
}
void dequeue(){
    if(isEmpty()){
        cout<<" queue underflow "<<endl;
    }
    cout<<arr[front]<<" has been removed "<<endl;
    if(front==rear){
        front=rear=-1;
    }
    else{
        front++;
    }
}
int peek(){
    if(isEmpty()){
        cout<<"queue underflow "<<endl;
        return -1;
    }
return arr[front];
}
void display(){
    if(isEmpty()){
        cout<<" queue is empty "<<endl;
        return;
    }
    for(int i=front;i<=rear;i++){
        cout<<arr[i]<<endl;
    }
}
 };
 int main() {
 //Write your C++ code here
 cout << "Hello, World!" << endl;
 return 0;
 }

No comments:

Post a Comment

MergeSort

  #include < iostream >   using namespace std ;   void merge ( vector < int >& n , int low , int mid , int high ){   ...