import java.util.*;
class DuiLie
{
private LinkedList<String> link;
DuiLie()
{
link = new LinkedList<String>();
}
public void myAdd(String s)
{
link.addFirst(s);
}
public String myGet()
{
//return link.removeLast();
return link.removeFirst();
}
public boolean isNull()
{
return link.isEmpty();
}
}
class DuiLieDemo
{
public static void main(String[] args)
{
DuiLie dl = new DuiLie();
dl.myAdd("java01");
dl.myAdd("java02");
dl.myAdd("java03");
dl.myAdd("java04");
while(!dl.isNull())
{
System.out.println(dl.myGet());
}
}
} |
|