创建一个类.有一个linkedlist内容为空 用listIteratot 对这个list 用Integer填充
要求填充时Integer对象总是填充在中间
eg:
第一次后填充
内容为:0第二次后填充
内容为:1,0第三次后填充
内容为:1,2,0第四次后填充
内容为:1,3,2,0第五次后填充
内容为:1,3,4,2,0
要求填充时Integer对象总是填充在中间
eg:
第一次后填充
内容为:0第二次后填充
内容为:1,0第三次后填充
内容为:1,2,0第四次后填充
内容为:1,3,2,0第五次后填充
内容为:1,3,4,2,0
void addmiddle(Integer e){
int middle = this.size() / 2;
this.add(middle,e);
}
void addMiddle(Integer e){
add(size()/2,e);
}
我总是忍不住写this……
LinkedList list = new LinkedList();
for(int i =0 ; i<5 ;i++){
list.add(list.size()/2 , new Integer(i));
}
System.out.println(Arrays.toString(list.toArray()));
}
}有什么别的办法吗,没有用到listIterator