📄 testlink.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;
}
}
public class TestLink
{
public static void main(String args[])
{
Link l = new Link();
l.add("a");
l.add("b");
l.addFirst("c");
l.addLast("d");
System.out.println(l.getFirst());
System.out.println(l.getLast());
System.out.println(l.getSize());
l.removeFirst();
l.removeLast();
System.out.println(l.getFirst());
System.out.println(l.getLast());
System.out.println(l.getSize());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -