package practise;
public class Node
{
public int data;
public Node next;
public Node (int data, Node next)
{
this.data = data;
this.next = next;
}
public int size (Node list)
{
int count = 0;
while(list != null){
list = list.next;
count++;
}
return count;
}
public static Node insert(Node head, int value)
{
Node T;
if (head == null || head.data <= value)
{
T = new Node(value,head);
return T;
}
else
{
head.next = insert(head.next, value);
return head;
}
}
}
这适用于小于第一个或头部的所有数据值。任何大于 的东西都不会被添加到列表中。因此,例如在我的主要方法 Node root = new Node(200,null) 中,我现在创建的大于 200 的任何节点都不会被添加。请用简单的术语解释一下,谢谢。