Advertisement
AvengersAssemble

Lab-18-02

Feb 18th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.08 KB | None | 0 0
  1. using System;
  2. using Unit4.CollectionsLib;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Lab_18_02
  7. {
  8.     class Program
  9.     {
  10.         public static bool Twins(BinTreeNode<int> t)
  11.         {
  12.             if (t.GetLeft().GetInfo() == t.GetRight().GetInfo())
  13.                 return true;
  14.             return false;
  15.         }
  16.  
  17.         public static bool HorimAhim(BinTreeNode<int> t)
  18.         {
  19.             if (t.GetInfo() == t.GetLeft().GetInfo() || t.GetInfo() == t.GetRight().GetInfo())
  20.                 return true;
  21.             return false;
  22.         }
  23.  
  24.         public static bool Check(BinTreeNode<int> t)
  25.         {
  26.             if (t.GetRight() == t.GetLeft())
  27.                 return true;
  28.             if ((t.GetRight() == null && t.GetLeft() != null) || (t.GetLeft() == null && t.GetRight() != null))
  29.                 return false;
  30.             if (!Twins(t) && !HorimAhim(t))
  31.                 return Check(t.GetLeft()) && Check(t.GetRight());
  32.             return false;
  33.  
  34.         }
  35.  
  36.         // טענת כניסה: הפעולה מקבלת עץ בינארי של מספרים שלמים
  37.         // טענת יציאה: הפעולה מחזירה את גובה העץ
  38.         // סיבוכיות זמן ריצה: O(n)
  39.         public static int Height(BinTreeNode<int> bt)
  40.         {
  41.             if (bt == null)
  42.                 return -1;
  43.             return 1 + Math.Max(Height(bt.GetLeft()), Height(bt.GetRight()));
  44.         }
  45.  
  46.         // טענת כניסה: הפעולה מקבלת עץ בינארי של מספרים שלמים ומספר שלם המייצג רמה בעץ
  47.         // טענת יציאה: הפעולה מחזירה את מספר הצמתים ברמה שהתקבלה
  48.         // סיבוכיות זמן ריצה: O(n)
  49.         public static int NodesInLevel(BinTreeNode<int> bt, int level)
  50.         {
  51.             if (bt == null)
  52.                 return 0;
  53.             if (level == 0)
  54.                 return 1;
  55.             return NodesInLevel(bt.GetLeft(), level - 1) + NodesInLevel(bt.GetRight(), level - 1);
  56.         }
  57.  
  58.         //סיבוכיות זמן ריצה: O(n^2)
  59.         public static bool Check2(BinTreeNode<int> t)
  60.         {
  61.             if (t.GetLeft() == t.GetRight())
  62.                 return true;
  63.             int h = Height(t);
  64.             for (int i = 1; i <= h; i++)
  65.                 if (NodesInLevel(t, i) != i)
  66.                     return false;
  67.             return true;
  68.         }
  69.         static void Main(string[] args)
  70.         {
  71.             DateTime t;
  72.             while (true)
  73.             {
  74.                 t = DateTime.Now;
  75.                 t = t.AddMinutes(-44);
  76.                 if (t.Hour < 10)
  77.                     Console.Write("0");
  78.                 Console.Write(t.Hour + ":");
  79.                 if (t.Minute < 10)
  80.                     Console.Write("0");
  81.                 Console.Write(t.Minute + ":");
  82.                 if (t.Second < 10)
  83.                     Console.Write("0");
  84.                 Console.WriteLine(t.Second);
  85.                 System.Threading.Thread.Sleep(1000);
  86.                 Console.Clear();
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement