Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct queue
- {
- uint32_t cursor_start = 0;
- uint32_t cursor_end = 0;
- int64_t array[100000];
- //////////////////
- void push(const int64_t& n)
- {
- array[cursor_end++] = n;
- }
- //////////////////
- int64_t pop()
- {
- return array[cursor_start++];
- }
- /////////////////
- int64_t front()
- {
- return array[cursor_start];
- }
- ///////////////////
- int64_t size()
- {
- return cursor_end-cursor_start;
- }
- ////////////////
- void clear()
- {
- cursor_start = 0;
- cursor_end = 0;
- }
- };
- int main() {
- queue primer;
- string stroka;
- while (cin >> stroka)
- if (stroka == "push")
- {
- int64_t vr;
- cin >> vr;
- primer.push(vr);
- cout << "ok" << endl;
- }
- else if(stroka == "pop")
- {
- if(primer.size() == 0)
- {
- cout << "error" << endl;
- }
- else
- {
- cout << primer.pop() << endl;
- }
- }
- else if(stroka == "front")
- {
- if(primer.size() == 0)
- {
- cout << "error" << endl;
- }
- else
- {
- cout << primer.front() << endl;
- }
- }
- else if(stroka == "size")
- {
- cout << primer.size() << endl;
- }
- else if(stroka == "clear")
- {
- primer.clear();
- cout << "ok" << endl;
- }
- else if(stroka == "exit")
- {
- cout << "bye";
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement