单选题

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

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();

      }

}

A

栈 s 的输出顺序是 1 2 3 4 5 ,队列 q 的输出顺序是 5 4 3 2 1 。

B

栈 s 的输出顺序是 5 4 3 2 1 ,队列 q 的输出顺序是 1 2 3 4 5 。

C

栈 s 的输出顺序是 1 2 3 4 5 ,队列 q 的输出顺序是 1 2 3 4 5 。

D

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

赣ICP备20007335号-2