📄 stacktest.java.bak
字号:
import java.util.*;
class MyStack {
int keyWord;
MyStack next;
public MyStack(int keyWord,MyStack next){
this.keyWord = keyWord;
this.next = next;
}
public MyStack(int keyWord){
this.keyWord = keyWord;
this.next = null;
}
}
public class StackTest {
MyStack sk = null;
public void push(int count){
MyStack q = sk;
if(sk == null)
sk = q = new MyStack(count);
else{
//MyStack p = new MyStack(count,q);
//sk = p;
MyStack p = new MyStack(count);
p.next = q;
sk = p;
}
}
public int pop(){
int count = 0;
if(sk != null){
//System.out.println(sk.keyWord);
count = sk.keyWord;
//return sk.keyWord;
MyStack q = sk;
sk = q.next;
q.next = null;
q = null;
}//end if
else{
System.out.println("the stack is empty");
return -1;
}
//return -1;
return count;
}
public void listElements(){
MyStack q = sk;
while(q != null){
System.out.println("list : "+q.keyWord);
q = q.next;
}
}
public static void main(String[] args){
StackTest test = new StackTest();
/*test.push(1);
System.out.println("list now ");
test.listElements();
System.out.println(test.pop());
System.out.println(test.pop());
test.push(2);
System.out.println("list now ");
test.listElements();
System.out.println(test.pop());
test.push(3);
test.push(4);
//System.out.println(test.pop());
//System.out.println(test.pop());
System.out.println("list now ");
test.listElements();
*/
test.push(1);
test.push(2);
test.push(3);
test.push(5);
System.out.println(test.pop());
System.out.println(test.pop());
//System.out.println(test.pop());
test.listElements();
test.push(6);
test.push(7);
test.listElements();
test.pop();
test.listElements();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -