לפניך הפעולה Check(t1, t2) ב-C#. הפעולה מקבלת שני עצים בינריים לא ריקים מטיפוס שלם, t1 ו-t2, ומחזירה רשימה המכילה את כל המספרים הנמצאים בעץ t1 ואינם נמצאים בעץ t2. הפעולה מזמנת פעולה נוספת המקבלת שלושה פרמטרים.
לפניך הפעולה Check(t1, t2) ב-C#. הפעולה מקבלת שני עצים בינריים לא ריקים מטיפוס שלם, t1 ו-t2, ומחזירה רשימה המכילה את כל המספרים הנמצאים בעץ t1 ואינם נמצאים בעץ t2. הפעולה מזמנת פעולה נוספת המקבלת שלושה פרמטרים.
public class BinNode<T> {
private T value;
private BinNode<T> left;
private BinNode<T> right;
public BinNode(T value) { this.value = value; this.left = null; this.right = null; }
public T GetValue() { return value; }
public void SetValue(T value) { this.value = value; }
public BinNode<T> GetLeft() { return left; }
public void SetLeft(BinNode<T> left) { this.left = left; }
public BinNode<T> GetRight() { return right; }
public void SetRight(BinNode<T> right) { this.right = right; }
}
public class Node<T> {
private T value;
private Node<T> next;
public Node(T value) { this.value = value; this.next = null; }
public T GetValue() { return value; }
public void SetValue(T value) { this.value = value; }
public Node<T> GetNext() { return next; }
public void SetNext(Node<T> next) { this.next = next; }
}
// הפעולה Check(t1,t2) הבאה נתונה (אינה חלק מהמימוש):
public static Node<int> Check(BinNode<int> t1, BinNode<int> t2) {
Node<int> first = new Node<int>(-1);
first = Check(t1, t2, first);
return first.GetNext();
}
ממש פעולה חיצונית exist ב-Java (או Exist ב-C#). הפעולה מקבלת עץ בינרי t וערך x, ומחזירה true אם x קיים בעץ, אחרת false.
public static bool Exist (BinNode<int> t, int x)
לפניך הפעולה check(t1, t2) (הפעולה מקבלת שני עצים בינריים לא ריקים t1 ו-t2, ומחזירה רשימה חדשה (Node<Integer>) המכילה את כל המספרים הנמצאים בעץ t1 ואינם נמצאים בעץ t2). הפעולה נעזרת בפעולה נוספת בעלת שלושה פרמטרים. ממש את הפעולה: public static Node<Integer> check(BinNode<Integer> t1, BinNode<Integer> t2, Node<Integer> list) (ב-C#: Check(BinNode<int> t1, BinNode<int> t2, Node<int> list)). אתה יכול להשתמש בפעולה שמימשת בסעיף א.
public static Node<int> Check (BinNode<int> t1, BinNode<int> t2, Node<int> list)
מהי סיבוכיות זמן הריצה של הפעולה שמימשת בסעיף ב? נמק את תשובתך.
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.