class MyStack {
/** Initialize your data structure here. */
public MyStack() {
Queue <> q = new Linkedlist <>;
}
/** Push element x onto stack. */
public void push(int x) {
q.poll(x);
}
/** Removes the element on top of the stack and returns that element. */
public int pop() {
for (int i = 0; i < q.length-2 ;i++){
int a = q.poll();
q.offer(a);
}
q.poll();
}
/** Get the top element. */
public int top() {
public int pop() {
for (int i = 0; i < q.length-2 ;i++){
int a = q.poll();
q.offer(a);
}
q.peek();
}
/** Returns whether the stack is empty. */
public boolean empty() {
if (q.isEmpty()){
return True;
else
return false;
}
}
博客内容展示了一个自定义的栈类MyStack,在信息技术领域,栈是重要的数据结构,该类的定义可能用于后续栈相关操作的实现。
3732

被折叠的 条评论
为什么被折叠?



