二叉树学生系统

时间:2014-12-24 21:14:14

标签: java data-structures binary-tree

请帮助我,如何插入,查找节点或在所有学生中搜索'数据

插入,findNode和搜索方法中的错误是什么?

它在所有"数据"上显示错误变量"

public class KAUstudent {

private int id;
private String fname;
private String lname;
 private String email;
 private int age;
  private int phone;
   private int level;
   private KAUcourses courses;
   private double gpa;
   private KAUstudent left;
   private KAUstudent right;
   private  KAUstudent data;

   public KAUstudent()
   {
       left=right=null;
   }

   public KAUstudent(KAUstudent st)
   {
       left=right=null;
   } 

   public int get_id(){return id;}
   public void set_id(int id){this.id=id;}

   public String get_fname(){return fname;}
    public void set_fname(String fname){this.fname=fname;}

 public String get_lname(){return lname;}
 public void set_lname(String lname){this.lname=lname;}

 public String get_email(){return email;}
 public void set_email(String email){this.email=email;}

 public int get_age(){return age;}
 public void set_age (int age){this.age=age;}


  public int get_phone(){return phone;}
  public void set_phone(int phone){this.phone=phone;}

   public int get_level(){return level;}
   public void set_level(int level){this.level=level;}

   public KAUcourses get_courses(){return courses;}
   public void set_courses(KAUcourses courses){this.courses=courses;}

   public double get_gpa(){return gpa;}
   public void set_gpa(double gpa){this.gpa=gpa;}

   public KAUstudent get_left(){return left;}
   public void set_left(KAUstudent left){this.left=left;}

   public KAUstudent get_right(){return right;}
   public void set_right(KAUstudent right){this.right=right;}

   public KAUstudent getData()
   {
       return data;
   }

   public void setData(int id,String fname,String lname,String email,int age,int phone,int level,KAUcourses courses,double gpa)
   {
       data.id=id;
         data.left=right=null;

        data.fname=fname;
       data.lname=lname;
       data.email=email;
       data.age=age;
       data.phone=phone;
       data.level=level;
       data.courses=courses;
       data.gpa=gpa;
   } 
    }


public class KAUdbmsBST {    
private KAUstudent root;


public KAUdbmsBST()
{
    root = null;
}

public boolean isEmpty( )
{
    return root == null;
}

public boolean search(  KAUstudent data ){return search(root, data);}


    private boolean search(KAUstudent p, int data) 
    {
    if (p == null)
        return false;
    else {

        if (data == p.getData())
            return true;
        else if (data <p.getData())
            return search(p.get_left(), data);
        else
            return search(p.get_right(), data);
                }
}

public KAUstudent findNode(KAUstudent data) {
    return findNode(root, data);
}

 private KAUstudent findNode(KAUstudent p, KAUstudent data) 
 {
    if (p == null)
        return null;
    else {

        if (data == p.getData())
            return p;
        else if (data < p.getData())
            return findNode(p.get_left(), data);
        else
            return findNode(p.get_right(), data);
                }
}

   public void insert(KAUstudent data)
{
        KAUstudent newNode = new KAUstudent(data);
        root = insert(root, newNode);
}

   public void KAUstudent insert (KAUstudent p, KAUstudent newNode) {

    if (p == null)
        return newNode;
    else {

        if (newNode.getData() > p.getData()) 
                    {               
            KAUstudent temp = insert(p.get_right(), newNode);

            p.setRight(temp);
        }

        else {              

            KAUstudent temp = insert(p.get_left(), newNode);

            p.set_left(temp);
                        }
    }
return p;
}

我希望有人可以帮助我。 提前谢谢

1 个答案:

答案 0 :(得分:1)

我认为,您为多个DATA-TYPES使用相同的变量名称; 即使用int数据和KAUstudent数据;