#3747. [GESP202412 六级 C++] 第 4 题

[GESP202412 六级 C++] 第 4 题

阅读以下代码,下面哪一项是正确的?

void processData() {
    stack<int> s;
    queue<int> q;
    for (int i = 1; i <= 5; ++i) {
        s.push(i);
        q.push(i);
    }
    while (!s.empty()) {
        cout << "Stack pop: " << s.top() << endl;
        s.pop();
    }
    while (!q.empty()) {
        cout << "Queue pop: " << q.front() << endl;
        q.pop();
    }
}

{{ select(1) }}

  • s 的输出顺序是 1 2 3 4 5,队列 q 的输出顺序是 5 4 3 2 1
  • s 的输出顺序是 5 4 3 2 1,队列 q 的输出顺序是 1 2 3 4 5
  • s 的输出顺序是 1 2 3 4 5,队列 q 的输出顺序是 1 2 3 4 5
  • s 的输出顺序是 1 2 3 4 5,队列 q 的输出顺序是 1 2 3 4 5,程序不会正常执行。