用java写的单向链表,第一个数据元素节点无法插入!!
public class Node { Object element; Node next; public Node(Object element){ this.element=element; } public Node(Object element, Node next) { super(); this.element = element; this.next = next; } public Object getElement() { return element; } public void setElement(Object element) { this.element = element; } public Node getNext() { return next; } public void setNext(Node next) { this.next = next; }}public class LinList { private Node head;//头指针 private Node current;//当前指针 private int size;//单链表的长度 public LinList(){ head=current=new Node(null); size=0; } public void index(int i){//移动current指针的方法 if(isize-1){ System.out.println("paraments is wrong"); } if(i==-1){ return; } current=head.getNext(); for(int j=0;current!=null&&j |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|
题主用IDE编辑的时候没报错吗?LinList的head成员是private的,理论上不能直接操控... |
|
|
|
|