标签:style blog http color os 数据 ar 2014
1:2: package cn.cqu.huang;
3:4: public class SingleList {5: private int data; //数据域6: private SingleList next; //指针域7:8: public SingleList(int x){9: data = x;10: }11:12: public void append(SingleList x){ //在链表末尾增加一个元素13: SingleList p = this; //使p指向当前节点14: while(p.next!=null){15: p = p.next;16: }17: p.next = x;18: }19:20: public void add(SingleList x){ //在当前节点的后面添加一个节点21: x.next = next;22: next = x;23: }24:25: public void show(SingleList x){26: SingleList p = this;
27: while(p!=null){28: System.out.println(p.data);29: p = p.next;30: }31: }32:33:34: public static void main(String[] args){35: SingleList list = new SingleList(10);
36: list.append(new SingleList(20)); //在list节点后面增加节点37: list.append(new SingleList(30));
38: list.append(new SingleList(40));
39:40: list.add(new SingleList(50)); //在list节点前面增加节点41: list.append(new SingleList(60));
42:43: list.show(list);44: }45: }
标签:style blog http color os 数据 ar 2014
原文地址:http://www.cnblogs.com/wyhuang/p/3917544.html