Пример #1
0
        public static int[] heapSort(MinHeapDouble minHeap)
        {
            int[] newIndices = new int[minHeap.getIndices().Length];
            int   orgsize    = minHeap.size;

            for (int i = 0; i < orgsize; ++i)
            {                                        // Now sort
                newIndices[i] = minHeap.removeMin(); // removeMax places max value at end of heap
            }
            return(newIndices);
        }
Пример #2
0
        public HeapSortDouble(int heapSize, bool bDescending = true)
        {
            if (heapSize == 0)
            {
                throw new ArgumentException();
            }
            this.heapSize = heapSize;
            //this.bDescending = bDescending;
            if (!bDescending)
            {
                factor = -1;
            }

            mhd = new MinHeapDouble(heapSize);
            for (int i = 0; i < heapSize; i++)
            {
                mhd.insert(-1, double.MinValue);
            }
        }
Пример #3
0
        public List <T> GetTopIndices()
        {
            if (!isSort)
            {
                MinHeapDouble.heapSort(mhd);
                isSort = true;
            }

            int[] indices  = mhd.getIndices();
            var   itemList = new List <T>();

            Dictionary <int, double> dict = new Dictionary <int, double>();

            for (int i = 0; i < heapSize; i++)
            {
                if (indices[i] != -1)
                {
                    itemList.Add(_itemList[indices[i]]);
                }
            }

            return(itemList);
        }
Пример #4
0
        public Dictionary <T, double> GetSortedDictionary()
        {
            if (!isSort)
            {
                MinHeapDouble.heapSort(mhd);
                isSort = true;
            }

            int[]    indices = mhd.getIndices();
            double[] values  = mhd.getValues();

            Dictionary <T, double> dict = new Dictionary <T, double>();

            for (int i = 0; i < heapSize; i++)
            {
                if (indices[i] != -1)
                {
                    dict.Add(_itemList[indices[i]], factor * values[i]);
                }
            }

            return(dict);
        }