using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class UzelBVS { public int hodnota; public UzelBVS L, P; public UzelBVS(int hodnota) { this.hodnota = hodnota; L = null; P = null; //nemusel bych dosazovat, uz to tam je } } class BVS { UzelBVS koren; public int pocet; void insert(int hodnota, ref UzelBVS kam) { if (kam == null) { kam = new UzelBVS(hodnota); pocet++; } else if (hodnota < kam.hodnota) insert(hodnota, ref kam.L); else if (hodnota > kam.hodnota) insert(hodnota, ref kam.P); else ; // nic, uz tam je } public void Insert(int hodnota) { insert(hodnota, ref koren); } public void Vytiskni(UzelBVS uzel) { if (uzel != null) { Vytiskni(uzel.L); Console.Write("{0} ", uzel.hodnota); Vytiskni(uzel.P); } } public void Vytiskni() { Vytiskni(koren); } } class Program { static void Main(string[] args) { for (int velikost = 1; velikost <= 100; velikost++) { Random rnd = new Random(1234); int[] pole; pole = new int[10000 * velikost + 1]; int pocet = 0; BVS bvs = new BVS(); System.Collections.Hashtable ht = new System.Collections.Hashtable(); DateTime start = DateTime.Now; for (int i = 1; i < 10000 * velikost; i++) { int x = rnd.Next(1000 * 1000 * 1000); /* */ pole[pocet] = x; int j = 0; while (pole[j] != x) j++; if (j == pocet) pocet++; /* */ //bvs.Insert(x); if (!ht.ContainsKey(x)) ht.Add(x, ht); } TimeSpan ts = DateTime.Now - start; Console.WriteLine("{0}0.000: {1}x {2}ms", velikost, pocet, ts.TotalMilliseconds); //Console.WriteLine("{0}0.000: {1}x {2}ms", velikost, bvs.pocet, ts.TotalMilliseconds); //Console.WriteLine("{0}0.000: {1}x {2}ms", velikost, ht.Count, ts.TotalMilliseconds); } } } }