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 を超えるノードで作成したノードは追加されません。簡単な言葉で説明してください。