Exemple #1
0
        public int[] HeapSortExternal(Node[] nodes)
        {
            Heap heap = new Heap();

            heap.HeapExternal(nodes);
            heap.HeapSort();
            return(heap.toArray());
        }
Exemple #2
0
 private void ButtonSort_Click(object sender, EventArgs e)
 {
     int[] sortArray;
     ButtonConvertToHeap_Click(sender, e);
     if (graph != null && graph.GetVertices.Count > 0)
     {
         sortArray             = heap.HeapSort(graph.GetArrayView);
         textBoxArraySort.Text = null;
         for (int i = sortArray.Length - 1; i >= 0; i--)
         {
             textBoxArraySort.Text += sortArray[i] + " ";
         }
     }
 }
Exemple #3
0
        public static void testInternal(byte[] bytes, string name, int size)
        {
            Stopwatch stopwatch = new Stopwatch();
            Heap      heap      = new Heap();
            Random    rnd       = new Random();

            for (int i = 0; i < size; i++)
            {
                Node node = new Node(rnd.Next(0, i), false);
                heap.Add(node);
            }

            stopwatch.Start();
            heap.HeapSort();
            stopwatch.Stop();

            TimeSpan ts           = stopwatch.Elapsed;
            string   elapsedTimeI = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

            Console.WriteLine("RunTime " + elapsedTimeI);
        }
        static void Main(string[] args)
        {
            int[] v    = { 55, 31, 5, 79, 1, 21, 22, 19, 66, 35 };
            Heap  sort = new Heap();

            sort.HeapSort(v);
            for (int i = 0; i < v.Length; i++)
            {
                Console.WriteLine(v[i]);
            }
            Console.WriteLine("Generic:");
            double[] k = { 23.5, 23.6, 29, 33, -1 };
            GenericHeapSort <double> hp = new GenericHeapSort <double>();

            hp.HeapSort(k);
            for (int i = 0; i < k.Length; i++)
            {
                Console.WriteLine(k[i]);
            }

            Console.ReadKey();
        }
Exemple #5
0
        public static void Internal(byte[] bytes, string name)
        {
            int width  = BitConverter.ToInt32(bytes, 0x0012);
            int height = BitConverter.ToInt32(bytes, 0x0016);

            int[] bs   = new int[width * height];
            Heap  heap = new Heap();
            int   j    = 54;

            for (int i = 0; i < bs.Length; i++)
            {
                bs[i] = (((bytes[j + 2] << 8) + bytes[j + 1]) << 8) + bytes[j];
                Node node = new Node(bs[i], false);
                heap.Add(node);
                j += 3;
            }

            heap.HeapSort();

            j = 54;
            foreach (var n in DiagonalOrder.Diagonal(heap.toArray(), height, width))
            {
                byte[] p = BitConverter.GetBytes(n);
                bytes[j]     = p[0];
                bytes[j + 1] = p[1];
                bytes[j + 2] = p[2];
                j           += 3;
            }

            using (FileStream file2 = new FileStream(name + "_sorted.bmp", FileMode.Create, FileAccess.Write))
            {
                file2.Seek(0, SeekOrigin.Begin);
                file2.Write(bytes, 0, bytes.Length);
                file2.Close();
            }
        }