我需要使用递归搜索堆栈中的元素我不能使用其他数据结构我无法更改堆栈这是我所做的,这是错误的
public static<E> boolean se(LinkedStack<E>s,E a) {
boolean answer=false;
E tmp=s.pop();
if(tmp==a)
answer= true;
else {
se(s, a);
s.push(tmp);
}
return answer;
}
public static<E> boolean se(LinkedStack<E>s,E a) {
boolean answer=false;
E tmp=s.pop();
if(tmp==a)
answer= true;
else {
answer = se(s, a);
s.push(tmp);
}
return answer;
}