Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int SIZE = 101;
- int que[SIZE] = {};
- int head, tail;
- void push(int x)
- {
- que[head] = x;
- head = (head + 1) % SIZE;
- }
- void pop()
- {
- tail = (tail + 1) % SIZE;
- }
- int front()
- {
- return que[tail];
- }
- int size()
- {
- return (head + SIZE - tail) % SIZE;
- }
- void clear()
- {
- head = tail = 0;
- }
- int main()
- {
- string command;
- while(1)
- {
- cin >> command;
- if (command == "exit") break;
- if (command == "pop")
- {
- cout << front();
- pop();
- }
- else if (command == "front")
- {
- cout << front();
- }
- else if (command == "size")
- {
- cout << size();
- }
- else if (command == "clear")
- {
- clear();
- cout << "ok";
- }
- else if (command == "push")
- {
- int x;
- cin >> x;
- push(x);
- cout << "ok";
- }
- cout << endl;
- }
- cout << "bye";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement