前提・実現したいこと
Node.java の #maxItem と #minItem を実装したいのですが、lsub と rsub の最初の数字を表示する方法が分かりません。lsub は、root の下にある左側の二分木全体を表しています。(rsub は右側です。)
下のコードの、"左の数字"、"右の数字"というところに、それぞれ最初の数字を表示したいです。
Node.java
java
1public class Node implements IBT { 2 3 private int root; 4 private IBT lsub; 5 private IBT rsub; 6 7 public Node(int root, IBT lsub, IBT rsub) { 8 if (root == null || lsub == null || rsub == null) { 9 throw new IllegalArgumentException(); 10 } 11 12 this.root = root; 13 this.lsub = lsub; 14 this.rsub = rsub; 15 } 16 17 18 19 public boolean isEmpty() { 20 return false; 21 } 22 23 24 public int getRoot() { 25 return this.root; 26 } 27 28 public IBT getLSub() { 29 return this.lsub; 30 } 31 32 public IBT getRSub() { 33 return this.rsub; 34 } 35 36 37 public Integer maxItem() { 38 int max = this.root(); 39 if (max < 左の数字) { 40 max = 左の数字; 41 return max; 42 } else if (max < 右の数字) { 43 max = 右の数字; 44 return max; 45 } else { 46 return max; 47 } 48 } 49 50 public Integer minItem() { 51 int min = this.root(); 52 if (min > 左の数字) { 53 min = 左の数字; 54 return min; 55 } else if (min > 右の数字) { 56 min = 右の数字; 57 return min; 58 } else { 59 return min; 60 } 61 } 62 63}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/28 19:50