这是我的班级,我想对我的堆栈进行排序,但它会抛出异常请帮助我谢谢!
public class jj {
public static void main(String[] args){
Stack<Integer> s = new ImplimentingAStackUsingAnArrayOfAGivenSizeN(5);
s.push(1);
s.push(3);
s.push(5);
s.push(2);
s.push(4);
Collections.sort((List<Integer>) (s));
System.out.println(s);
while (!s.isEmpty()) {
System.out.println(s.pop());
}
}
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
Exception in thread "main" java.lang.ClassCastException:
datastructurechapter5.ImplimentingAStackUsingAnArrayOfAGivenSizeN
cannot be cast to java.util.List at datastructurechapter5.jj.main(jj.java:24)
`Collections.sort((List<Integer>) (s));`
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
Run Code Online (Sandbox Code Playgroud)