コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: iggyglass/HeapTree
        public void Empty()
        {
            HeapTree <int> tree = new HeapTree <int>(5);

            Assert.True(tree.IsEmpty());

            tree.Insert(5);

            Assert.False(tree.IsEmpty());
        }
コード例 #2
0
ファイル: HeapSort.cs プロジェクト: iggyglass/HeapTree
        /// <summary>
        /// Sorts array
        /// </summary>
        /// <param name="arr">The array to be sorted</param>
        /// <returns>The sorted array</returns>
        public T[] Sort(T[] arr)
        {
            // Sort is done by continuing to pop value into new array
            HeapTree <T> tree = new HeapTree <T>(arr.Length);

            T[] ret = new T[arr.Length];
            int ap  = 0;

            // I need to insert into tree
            for (int i = 0; i < arr.Length; i++)
            {
                tree.Insert(arr[i]);
            }

            while (!tree.IsEmpty())
            {
                ret[ap] = tree.Pop();
                ap++;
            }

            return(ret);
        }