queuefrontback
quoc14
c_cpp
a year ago
681 B
9
Indexable
caidat
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
int queue[100111];
int front = 1;
int back = 1;
void insert(int x) {
queue[back] = x;
back++;
}
void pop() {
queue[front] = 0;
front++;
}
int getFront() {
return queue[front];
}
void show() {
for (int i = front; i < back; i++) {
cout << queue[i] << " ";
}
cout << endl;
}
bool isEmpty() {
return (front == back);
}
int main() {
// Write C++ code here
insert(2);
insert(3);
insert(4);
insert(5);
while (!isEmpty()) {
pop();
}
insert(6);
insert(7);
show();
return 0;
}Editor is loading...
Leave a Comment