# java实现单链表基本操作

用java语言实现单链表的基本操作。。。。

public class Mylink {

private int length;
private Node rear;
private Node p;

private class Node{
private Object data;
private Node next;

public Node(){
this.data = null;
}

public Node(Object e){
this.data = e;
}
}

//创建不带数据的头节点
length = 0;
}

//头插法创建链表

return;
}
Node node = new Node(e);
length++;
}

//尾插法创建链表
return;
}

Node node = new Node(e);
node.next = null;
rear.next = node;
rear = node;
length++;
}

//在第i位置插入值e
public void insert(int i,Object e){
return ;
}
int j = 0;
while(p!=null){
j++;
if(j==i){
Node node = new Node(e);
node.next = p.next;
p.next = node;
length++;
break;
}

p = p.next;
}

}

//删除第i个节点
public void deleteNode(int i){
return ;
}
int j = 0;
while(p.next!=null){
j++;
if(j == i){
p.next = p.next.next;
length--;
break;
}

p=p.next;
}
}

//求当前链表的长度为

return length;
}

//打印链表
public void print(){
while(p!=null){
System.out.print(p.data+"\t");
p = p.next;
}
System.out.println();
}

public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println("链表的初始值为：");

System.out.println("插入值后的链表为：");
}