码迷,mamicode.com
首页 > 其他好文 > 详细

单链表的

时间:2014-08-17 11:43:32      阅读:213      评论:0      收藏:0      [点我收藏+]

标签: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: }
bubuko.com,布布扣

bubuko.com,布布扣

单链表的,布布扣,bubuko.com

单链表的

标签:style   blog   http   color   os   数据   ar   2014   

原文地址:http://www.cnblogs.com/wyhuang/p/3917544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!