static void Main(string[] args) { Console.WriteLine("Drzewo BST"); int[] array0 = new int[] { 11, 15, 6, 8, 5, 1, 7, 13, 17, 14 }; DrzewoBST <int> drzewo0 = CreateTreeFromArray(array0); Console.WriteLine("In order:"); drzewo0.ShowInOrder(); Console.WriteLine(); Console.WriteLine("Pre-order: "); drzewo0.ShowPreOrder(); Console.WriteLine(); drzewo0.LeftRotation(15); Console.WriteLine("In order bez zmian"); drzewo0.ShowInOrder(); Console.WriteLine(); Console.WriteLine("Pre-order ze zmianami"); drzewo0.ShowPreOrder(); Console.WriteLine(); int[] array1 = new int[] { 16, 10, 6, 21, 20, 18, 13, 14, 17, 4, 11 }; DrzewoBST <int> drzewo1 = CreateTreeFromArray(array1); int[] array2 = new int[] { 10, 16, 12, 7, 9, 2, 21, 6, 17, 1, 15 }; DrzewoBST <int> drzewo2 = CreateTreeFromArray(array2); Console.ReadKey(); }
public static DrzewoBST <T> CreateTreeFromArray <T>(T[] array) where T : IComparable <T> { DrzewoBST <T> tree = new DrzewoBST <T>(); foreach (T item in array) { tree.Insert(item); } return(tree); }