السلام عليكم ،،
لو سمحتو يا أعضاء المنتدى ، محتاجة مساعدة في حل واجب في الـ bainary tree و نحن نستخدم برنامج NetBeans ،، و الأسئلة كالتالي:
1. Use a list class and node class which you created in the linked list lab for storing Course information, such as Course Code, Course Name and Grade.
2. Change the node class and make sure it has following fields only
public Node left;
public Node right;
public int data;
3. Modify the list class accordingly.
4. Create a class called Tree which creates a Binary Tree using list class and node class with the following values:-
60, 5, 20, 1, 50, 13, 80, 90, 70, 100, 10, 7
5. Create a method that takes one parameter of int type "number" and return the number of traversals it takes to search for "number" in the tree.
6. Create a method that takes one parameter of int type "number" and return an array of int having the values of all the children of subtree with root value equal to "number".
كل الأسئلة اللي اللي فوق حليتها ما عدا الأخير ،، راح أضيف لكم الكود اللي كتبته و اللي يتعلق بالسؤال الأخير ،، و إذا محتاجين أي أكواد ثانية أو أي شرح أنا مستعدة .. و هذا هو الكود :
if (root != null) {
if (root.getData() == no) {
return inorderTraversa(root);
}
if (no > root.getData()) {
if (no == root.getRight().getData()) {
return inorderTraversa(root.getRight());
} else {
root = root.getRight();
children(no);
}
} else {
if (no == root.getLeft().getData()) {
return inorderTraversa(root.getLeft());
} else {
root = root.getLeft();
children(no);
}
}
}
return arr;
}
public int[] inorderTraversa(Node a) {
return inorderHelper(a, 0);
}
private int[] inorderHelper(Node node, int i) {
// left node right
int[] a = new int[500];
if (node == null) {
return a;
}
inorderHelper(node.getLeft(), i++);
a = node.getData();
System.out.print(a + " ");
inorderHelper(node.getRight(), i++);
return a;
}
public int[] children(int no) {أتمنى منكم المساعدة !!



