#include <iostream>
using namespace std;
#include <queue>
#include <string>



int main() {
    int N=0;
    cin >> N;
    queue <int> q;
    string cmd;

    for(int i=0;i<N;i++) {
        cin >> cmd;
        if(cmd=="push") {
            int x=0;
            cin >> x;
            q.push(x);
        }

        else if(cmd=="pop") {
            if(q.empty()) {
                cout << -1 << endl;
            }

            else {
                cout << q.front() << endl;
                q.pop();
            }
        }

        else if(cmd=="size") {
            cout << q.size() << endl;
        }

        else if(cmd=="empty") {
            if(q.empty()) cout << 1 << endl;
            else cout << 0 << endl;
        }

        else if(cmd=="front") {
            if(q.empty()) cout << -1 << endl;
            else cout << q.front() << endl;
        }

        else if(cmd=="back") {
            if(q.empty()) cout << -1 << endl;
            else cout << q.back() << endl;
        }
    }    
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: