queue
quoc14
c_cpp
a month ago
738 B
3
Indexable
Never
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; }
Leave a Comment