原理图:
源代码:
NODE:
public class Node {
int data; //数据域
public Node next; //指针域
public Node(int value) {
// TODO Auto-generated constructor stub
this.data = value;
}
public void display() //显示结点的值
{
System.out.print(data + " ");
}
}
LinkList:
public class Linklist {
private Node first; //头结点
public Linklist() { //构造方法
// TODO Auto-generated constructor stub
first =null;
}
public void insert(int value) //头结点之前插入结点
{
Node node = new Node(value);
node.next = first;
first= node;
}
public void delete() //头结点后删除结点
{
Node tmp = first.next;
first.next = tmp.next;
}
public void display() //显示全部的结点
{
Node current = first;
while(current!= null)
{
current.display();
current = current.next;
}
System.out.println();
}
public void find(int value) //根据数值查找结点
{
Node current = first;
while(current.data != value)
{
current = current.next;
}
current.display();
}
public void findDele(int value) //查找数据并删除结点
{
Node current = first;
Node pro =current ;
if(first.data == value) //第一个就是的话
{
first = first.next;
}
else
{
while(current.data != value)
{
pro = current;
current = current.next;
}
pro.next = current.next;
}
}
}