LinkedList learns an example that simulates stack and queue data structures
- 2020-04-01 02:49:35
- OfStack
Stack: First in Last Out FILO is like a cup
Queue: First in First out FIFO Like a water pipe
class Duilie{
private LinkedList link;
Duilie(){
link = new LinkedList();
}
public void myAdd(Object obj){
link.addFirst(obj);
}
public Object myGet(){
return link.removeLast();//Change to removeLast so that it can be a transformation of the stack and queue
}
public boolean isNull(){
return link.isEmpty();
}
}
public class LinkedListTest {
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());
}
}
}