标签:list() color col his str main system class ati
public class Element { public Object object; public Element next = null; public Element(Object object){ this.object = object; } }
public class SingleLinkList { private Element element; public void init(){ element = new Element(null); element.next = null; } public void add(int data){ Element node = new Element(data); Element tmp = element; while (tmp.next != null){ tmp=tmp.next; } tmp.next = node; } public void display(){ Element tmp = element.next; while (tmp != null){ System.out.println("链表的值:" + tmp.object); tmp = tmp.next; } } }
public class Demo { public static void main(String[] args){ SingleLinkList sll = new SingleLinkList(); sll.init(); sll.add(1); sll.add(2); sll.add(3); sll.add(4); sll.add(5); sll.display(); } }
标签:list() color col his str main system class ati
原文地址:https://www.cnblogs.com/mutong1228/p/10759752.html