Exemple #1
0
        public static void testExternal(byte[] bytes, string name, int size, string xdir)
        {
            Stopwatch stopwatch = new Stopwatch();
            Heap      heap      = new Heap();
            External  external  = new External(xdir);
            Random    rnd       = new Random();

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

            int[] arr = heap.toArray();

            for (int i = 0; i < arr.Length; i++)
            {
                external.Add(arr[i]);
            }

            stopwatch.Start();
            heap.HeapSortExternal(external.toNodeArray(external));
            stopwatch.Stop();

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

            Console.WriteLine("RunTime " + elapsedTime);
        }
Exemple #2
0
        public static void External(byte[] bytes, string name, string xdir)
        {
            int width  = BitConverter.ToInt32(bytes, 0x0012);
            int height = BitConverter.ToInt32(bytes, 0x0016);

            int[]    bs       = new int[width * height];
            Heap     heap     = new Heap();
            External external = new External(xdir);
            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;
            }

            int[] arr = heap.toArray();

            for (int i = 0; i < arr.Length; i++)
            {
                external.Add(arr[i]);
            }

            j = 54;
            foreach (var n in DiagonalOrder.Diagonal(heap.HeapSortExternal(external.toNodeArray(external)), 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();
            }
        }