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