Exemple #1
0
 public void RemoveTest()
 {
     var hp = new Heap(8);
     hp.Add(-2);
     hp.Add(0);
     hp.Add(5);
     hp.Add(5);
     hp.Add(3);
     hp.Remove();
     string expected = String.Format("[ 0 3 5 5 {0} 0 0 0 ]", int.MaxValue);
     string actual = hp.ToString();
     Assert.AreEqual(actual, expected);
 }
Exemple #2
0
        public static void Sort(int[] a)
        {
            var hp = new Heap(a.Length);
            foreach (int n in a) {
                hp.Add(n);
            }

            for (int i = 0; i < a.Length; i++) {
                a[i] = hp.Remove();
            }
        }