算法与数据结构单选难度 3真题改编 · 2024
2575. 在一个学习教育中心,一位年轻的学生尝试对一个无向图G=(V,E)进行广度优先遍历。图中顶点集合为V={1, 2, 3, 4, 5, 6, 7},边集合为E={(1, 4), (2, 5), (1, 5), (4, 5), (3, 7), (4, 7), (2, 7), (2, 3), (3, 5), (5, 6)}。请问,无法得到的遍历序列是()
练习本题 ›
算法与数据结构栈单选难度 3真题改编 · 2024
2587. 下列程序的运行结果是( )
import java.util.*;
class Test{
public static void main(String[] args){
int[] pushA={1,2,4,5,3,6};
int[] popA1={4,5,2,3,1,6};
int[] popA2={4,6,5,2,3,1};
boolean res1=IsPopOrder(pushA,popA1);
boolean res2=IsPopOrder(pushA,popA2);
System.out.println(res1);
System.out.println(res2);
}
public static boolean IsPopOrder(int[] pushA,int[] popA){
if(pushA.length==0||popA.length==0) return false;
Stack<Integer> st=new Stack<Integer>();
int index=0;
for(int i=0;i<pushA.length;i++){
st.push(pushA[i]);
while(!st.empty()&&st.peek()==popA[index]){
st.pop();
index++;
}
}
return st.empty();
}
}
练习本题 ›
编程语言单选难度 3真题改编 · 2023
2594. def foo(a, b=2, *args, **kwargs):
print(a, b, args, kwargs)
foo(1, 3, 4, 5, x=6, y=7)
执行以上代码的输出结果为()
练习本题 ›