using namespace std;
#include<iostream>
#define N 5
class pq {
public:
int* arr;
int front;
int rear;
pq() {
front = -1;
rear = -1;
arr = new int[N];
}
int isEmpty() {
if((front == -1 && rear == -1) || (front > rear))
return 1;
else
return -1;
}
int isFull() {
if(rear == N -1)
return 1;
else
return -1;
}
void ins(int elt) {
if(isFull() == 1){
cout<<"Full"<<endl;
}else if((front == -1) && (rear == -1)){
front++;
rear++;
arr[rear] = elt;
} else {
if(arr[rear] > elt){
arr[rear + 1] = arr[rear];
arr[rear] = elt;
int current = rear;
rear++;
while(current!=front){
if(arr[current -1] > arr[current]){
int temp;
temp = arr[current -1];
arr[current -1] = elt;
arr[current] = temp;
}
current = current -1;
}
} else {
rear++;
arr[rear] = elt;
}
}
}
void del() {
if(isEmpty() == 1){
cout<<"Empty"<<endl;
} else {
front++;
}
}
void show() {
cout<<"\n____________________"<<endl;
for(int i = 0; i<N; i++){
cout<<arr[i];
}
}
};
int main() {
pq ob;
if(ob.isEmpty() == 1)
cout<<"isEmpty == Yes";
else
cout<<"isEmpty == NO";
ob.ins(4);
ob.ins(2);
ob.ins(1);
ob.ins(3);
ob.ins(5);
ob.show();
cout<<"xxx"<<ob.rear<<endl;
return true;
}
Wednesday, December 8, 2021
Priority queue deleting elements after ascending inputs Gaand Fadd
Subscribe to:
Post Comments (Atom)
Priority queue deleting elements after ascending inputs Gaand Fadd
using namespace std; #include<iostream> #define N 5 class pq { public: int* arr; int front; int rear; pq() { ...
-
using namespace std; #include<stdio.h> #define N 5 class q{ public: int* arr; int front; int rear; q() { ...
-
#include<stdio.h> int fnCmp(char* str1, char* str2) { while( (*str1 != '\0' && *str2 != '\0') && ...
-
#include<stdio.h> void fncpy(char* str2, char* str1) { int i = 0; while(*str1 != '\0') { str2[i] = *str1; ...
No comments:
Post a Comment