假设你执行了下列的栈操作:s = Stack()s.push(1)s.push(3)s.push(5)s.pop()s.push(7)现在栈内还有哪些元素?
A: 1, 5, 7
B: 3, 5, 7
C: 1, 3, 7
D: 1, 3, 5
A: 1, 5, 7
B: 3, 5, 7
C: 1, 3, 7
D: 1, 3, 5
C
举一反三
- 假设你执行了下列的栈操作:s = Stack()s.push(1)s.push(3)s.pop()s.push(5)s.push(7)现在栈内还有哪些元素?
- 栈S初始为空,进行一下操作后从栈顶到栈底的元素依次为:S.push(5);S.push(4);S.pop();S.push(2);S.pop();S.pop();S.push(1) A: 5, 4, 2, 1 B: 1, 2, 4, 5 C: 1 D: 5, 4
- 以下操作完成以后,栈S中从栈底到栈顶的元素依次是( )。InitStack(S);Push(S,5);GetTop(S,a);Push(S,3);Pop(S,b)Push(S,x+y) ; A: 5 3 B: 8 C: 5 3 8 D: 5 8
- 栈初始为空,依次经过以下操作: push(5); push(8); pop(); push(5); top(); push(1); push(3); pop(); pop(); push(2);此时从栈顶到栈底依次为: A: 2, 5, 5 B: 2, 3, 1 C: 5, 5, 2 D: 1, 3, 2
- 通过对堆栈S操作:Push(S,1),Push(S,2),Pop(S),Push(S,3),Pop(S),Pop(S)。输出的序列为:123。()
内容
- 0
对一个初始为空的栈s执行操作push(s,5),push(s,2),push(s,4),pop(s,x),getTop(s,x)后,x的值应是。
- 1
对一个初始为空的栈s执行操作Push(s,5), Push(s,2), Push(s,4), Pop(s,x), getTop(s,x)后,得到的值应是 。
- 2
对一个初始值为空的栈S,执行操作:Push(S,5),Push(S,2),Push(S,4),Pop(S,X),ReadTop(S,X)后,X的值应是
- 3
对一个初始为空的栈s执行操作Push(s,5),Push(s,2),Push(s,4),Pop(s,x),getTop(s,x)后,x的值应是( )。 A: 5 B: 4 C: 0 D: 2
- 4
经过下列栈的运算后,再执行ReadTop(s)的值是( )。 InitStack(s) (初始化栈);Push(s,a);Push(s,b); Pop(s) A: a B: b C: 1 D: 0