Exemple #1
0
 public void TravelStringBfsTest()
 {
     string expected = "-59 -45 11 -12 44 53 80 11 94 62 ";
     var hp = new Heap(a);
     string actual = hp.TravelString(isDfs: false);
     Assert.AreEqual(actual, expected);
 }
Exemple #2
0
 public void BuildTest()
 {
     string expected = "[ -59 -45 11 -12 44 53 80 11 94 62 ]";
     var hp = new Heap(a);
     string actual = hp.ToString();
     Assert.AreEqual(actual, expected);
 }
Exemple #3
0
 public void AddTest()
 {
     var hp = new Heap(8);
     hp.Add(-2);
     hp.Add(0);
     hp.Add(5);
     hp.Add(5);
     hp.Add(3);
     string expected = "[ -2 0 5 5 3 0 0 0 ]";
     string actual = hp.ToString();
     Assert.AreEqual(actual, expected);
 }
Exemple #4
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 #5
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();
            }
        }
Exemple #6
0
 public void TravelStringDfsTest()
 {
     string expected = "-59 -45 -12 11 94 44 62 11 53 80 ";
     var hp = new Heap(a);
     string actual = hp.TravelString(isDfs:true);
     Assert.AreEqual(actual, expected);
 }