-2
public static Node insert(Node root, int data)
if (root == null)
return new Node(data);
public static Node insert(Node root, int data)
if (root == null)
return new Node(data);
它返回一個「Node」對象,它由接受一個整數(本例中爲「data」)的新構造函數創建。
它返回對Node
類型的對象的引用。正如我從你的問題的標籤可以推斷出你正在處理一個樹型數據結構。此方法嘗試將節點插入樹中。如果樹中沒有其他節點,這將成爲樹的根。否則(root!=null
)應該實現一種方法,通過它將另一個(非根節點)添加到樹中。
這不是有效的Java語法! – Seelenvirtuose