下面给出了使用两个堆栈S1和S2的队列Q的实现:
null
void insert(Q, x) { push (S1, x); } void delete (Q){ if (stack-empty(S2)) then if (stack-empty(S1)) then { print(“Q is empty”); return ; } else while (!(stack-empty(S1))){ x=pop(S1); push(S2,x); } x=pop(S2); } |
设n insert和m(<=n)delete操作在空队列Q上以任意顺序执行。设x和y分别为该过程中执行的推送和弹出操作的数量。以下哪一项适用于所有m和n? (A) n+m<=x<2n和2m<=y<=n+m (B) n+m<=x<2n和2m<=y<=2n (C) 2m<=x<2n和2m<=y<=n+m (D) 2m<=x<2n和2m<=y<=2n 答复: (A) 说明: 等同于 https://www.geeksforgeeks.org/data-structures-queue-question-10/ 这个问题的小测验
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END