Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Unit4.CollectionsLib;
- using System.Linq;
- using System.Text;
- namespace Lab_18_02
- {
- class Program
- {
- public static bool Twins(BinTreeNode<int> t)
- {
- if (t.GetLeft().GetInfo() == t.GetRight().GetInfo())
- return true;
- return false;
- }
- public static bool HorimAhim(BinTreeNode<int> t)
- {
- if (t.GetInfo() == t.GetLeft().GetInfo() || t.GetInfo() == t.GetRight().GetInfo())
- return true;
- return false;
- }
- public static bool Check(BinTreeNode<int> t)
- {
- if (t.GetRight() == t.GetLeft())
- return true;
- if ((t.GetRight() == null && t.GetLeft() != null) || (t.GetLeft() == null && t.GetRight() != null))
- return false;
- if (!Twins(t) && !HorimAhim(t))
- return Check(t.GetLeft()) && Check(t.GetRight());
- return false;
- }
- // טענת כניסה: הפעולה מקבלת עץ בינארי של מספרים שלמים
- // טענת יציאה: הפעולה מחזירה את גובה העץ
- // סיבוכיות זמן ריצה: O(n)
- public static int Height(BinTreeNode<int> bt)
- {
- if (bt == null)
- return -1;
- return 1 + Math.Max(Height(bt.GetLeft()), Height(bt.GetRight()));
- }
- // טענת כניסה: הפעולה מקבלת עץ בינארי של מספרים שלמים ומספר שלם המייצג רמה בעץ
- // טענת יציאה: הפעולה מחזירה את מספר הצמתים ברמה שהתקבלה
- // סיבוכיות זמן ריצה: O(n)
- public static int NodesInLevel(BinTreeNode<int> bt, int level)
- {
- if (bt == null)
- return 0;
- if (level == 0)
- return 1;
- return NodesInLevel(bt.GetLeft(), level - 1) + NodesInLevel(bt.GetRight(), level - 1);
- }
- //סיבוכיות זמן ריצה: O(n^2)
- public static bool Check2(BinTreeNode<int> t)
- {
- if (t.GetLeft() == t.GetRight())
- return true;
- int h = Height(t);
- for (int i = 1; i <= h; i++)
- if (NodesInLevel(t, i) != i)
- return false;
- return true;
- }
- static void Main(string[] args)
- {
- DateTime t;
- while (true)
- {
- t = DateTime.Now;
- t = t.AddMinutes(-44);
- if (t.Hour < 10)
- Console.Write("0");
- Console.Write(t.Hour + ":");
- if (t.Minute < 10)
- Console.Write("0");
- Console.Write(t.Minute + ":");
- if (t.Second < 10)
- Console.Write("0");
- Console.WriteLine(t.Second);
- System.Threading.Thread.Sleep(1000);
- Console.Clear();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement