📄 teststack.java
字号:
class Node
{
private Object value;
private Node next ;
Node(Object value)
{
this.value = value;
next = null;
}
Node getNext()
{
return this.next;
}
void setNext(Node next)
{
this.next = next;
}
Object getValue()
{
return this.value;
}
}
class Link
{
private Node first;
private Node last;
private int i =0 ;
void add(Object o)
{
if(first==null)
{
last = first = new Node(o);
}
else
{
Node n = new Node(o);
last.setNext(n);
last = n;
}
i++;
}
void addFirst(Object o)
{
Node n = new Node(o);
n.setNext(first);
first = n;
i++;
}
void addLast(Object o)
{
add(o);
}
Object getFirst()
{
return first.getValue();
}
Object getLast()
{
return last.getValue();
}
void removeFirst()
{
first = first.getNext();
i--;
}
void removeLast()
{
Node n = first;
while(n.getNext()!=last)
{
n = n.getNext();
}
last = n;
i--;
}
int getSize()
{
return this.i;
}
}
class Tstack
{
private Link l;
Tstack()
{
this.l = new Link();
}
void push(Object o)
{
l.add(o);
}
Object pop()
{
Object o = l.getLast();
l.removeLast();
return o;
}
}
public class TestStack
{
public static void main(String args[])
{
Tstack t = new Tstack();
t.push("a");
t.push("b");
System.out.println(t.pop());
t.push("c");
System.out.println(t.pop());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -