2017-03-02 6 views
0

私はtrenaryツリーを実装しようとしていますが、次のエラーが発生しています。三元ツリーの実装でエラーが発生しました

エラー:必要な

Trenarytree.java:46: error: constructor Trenarytree in class Trenarytree cannot be applied to given types; 
    Trenarytree tree = new Trenarytree(1); 
        ^

:引数なし が見つかりました: 理由をint型:実際の仮引数リストの長さが 1つのエラー

コード異なります

import java.io.*; 
import java.util.*; 

public class Trenarytree { 

public int y = 0; 
public int count = 0; 
private static Node root; 

public void Trenarytree(int data) 
{ 
    root = new Node(data); 
} 

public void add(Node parent, Node child) 
{ 
    if (parent.getLeft() == null) 
    { 
     parent.setLeft(child); 
    } 
    else if (parent.getMiddle() == null){ 
     parent.setMiddle(child); 
    } 
    else 
    { 
     parent.setRight(child); 
    } 
} 

public Node sum(Node z){ 
    if (z.getLeft()!=null) y++; 
    if (z.getRight()!=null) y++; 
    if (z.getMiddle()!=null) y++; 
    if (y % 2 ==0){ 
     count++; 
    y=0;}; 
} 

public static void main(String[] args) { 
    /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ 
    Scanner sc = new Scanner (System.in); 
    int M = sc.nextInt(); 
    int N = sc.nextInt(); 
    int k, l; 
    Node[] array; 
    Trenarytree tree = new Trenarytree(1); 
    array[1] = new Node(1); 
    for (int i = 0; i < N; i++){ 
     k = sc.nextInt(); 
     l = sc.nextInt(); 
     array[k] = new Node(k); 
     if (i==1) tree.add(root, array[k]); 
      else tree.add(array[l], array[k]); 

    } 
} 
} 

class Node { 
private int key; 
private Node left; 
private Node right; 
private Node middle; 

Node (int key) { 
    this.key = key; 
    right = null; 
    left = null; 
    middle = null; 
} 

public void setKey(int key) { 
    this.key = key; 
} 

public int getKey() { 
    return key; 
} 

public void setLeft(Node left) { 
    this.left = left; 
} 


public Node getLeft() { 
    return left; 
} 

public void setMiddle(Node middle) { 
    this.middle = middle; 
} 

public Node getMiddle() { 
    return middle; 
} 
public void setRight(Node right) { 
    this.right = right; 
} 

public Node getRight() { 
    return right; 
} 

} 
+0

三ないtrenary https://en.wikipedia.org/wiki/Ternary_tree – javadba

+0

あなたは、インポートすることはありません。*図書館にない良い習慣「あなたは決してすべきである」守ることは困難ではないような –

+0

@RajHassaniステートメントを。すべてのシナリオを知っていますか?結局のところ、 'java.io/java.util'です。ここでは、クラスXはどこから来たのだろうと疑問に思うことはほとんどありません。 – javadba

答えて

3

をそれです空き:

public Trenarytree(int data) 

これはメソッドであり、それがなければコンストラクタです。

+0

今すべての意味があります。ありがとう –

2

コンストラクタTrenarytreeの定義からvoidを削除します。コンストラクターは何も返さず、構築されたオブジェクトを返します。

関連する問題