本帖最后由 1017161726 于 2015-5-5 23:10 编辑
大家关于我写代码的特点给点建议好吧、、thank-thank
堆栈特点是数据先进后出。
队列特点是数据先进先出。- import java.util.*;
- class Demo
- {
- public static void main(String [] args)
- {
- DuiLie dl=new DuiLie();
- dl.myAdd("java01");
- dl.myAdd("java02");
- dl.myAdd("java03");
- dl.myAdd("java04");
-
- DuiZhan dz=new DuiZhan();
- dz.myAdd("JAVA01");
- dz.myAdd("JAVA02");
- dz.myAdd("JAVA03");
- dz.myAdd("JAVA04");
-
- while (!dl.isNull())
- {
- System.out.println(dl.myGet());
- }
-
- while (!dz.isNull())
- {
- System.out.println(dz.myGet());
- }
- }
- }
- class DuiLie
- {
- private LinkedList link;
- DuiLie()
- {
- link=new LinkedList();
- }
- public void myAdd(Object oo)
- {
- link.addFirst(oo);
- }
- public Object myGet()
- {
- return link.removeLast();
- }
- public boolean isNull()
- {
- return link.isEmpty();
- }
- }
- class DuiZhan
- {
- private LinkedList link;
- DuiZhan()
- {
- link=new LinkedList();
- }
- public void myAdd(Object oo)
- {
- link.addFirst(oo);
- }
- public Object myGet()
- {
- return link.removeFirst();
- }
- public boolean isNull()
- {
- return link.isEmpty();
- }
- }
复制代码
|
|