少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
package com.abin.lee.list.test;
public class SingleList {
private Object obj;
private transient SingleList singleList;
private SingleList next;
private SingleList pre;
private transient int size;
public SingleList() {
singleList = new SingleList(null,null,null);
singleList.next = singleList.pre = singleList;
size=0;
}
public SingleList(Object obj,SingleList next,SingleList pre) {
this.obj=obj;
this.next=next;
this.pre=pre;
}
public void add(Object obj){
SingleList current = new SingleList(obj,singleList,singleList.pre);
current.next.pre = current;
current.pre.next = current;
size++;
singleList = current;
}
public int size(){
return size;
}
public Object get(int index){
SingleList current = singleList.next;
for(int i=0;i<index;i++){
current = current.next;
}
return current.obj;
}
public static void main(String[] args) {
SingleList single = new SingleList();
for(int i=0;i<5;i++){
single.add("abin"+i);
}
System.out.println("single="+single);
int size = single.size();
System.out.println("size="+size);
Object element = single.get(0);
System.out.println("element="+element);
}
}
posted on 2014-10-10 22:46 abin 阅读(332) 评论(0)  编辑  收藏 所属分类: algorithm

只有注册用户登录后才能发表评论。


网站导航: