1Data Structure:Heap Sort_i++using System;
 2Data Structure:Heap Sort_i++using System.Collections.Generic;
 3Data Structure:Heap Sort_i++using System.Text;
 4Data Structure:Heap Sort_i++
 5Data Structure:Heap Sort_i++namespace HeapSort
 6Data Structure:Heap Sort_i++_06Data Structure:Heap Sort_其他_07Data Structure:Heap Sort_i++_08{
 7Data Structure:Heap Sort_其他_09    class Program
 8Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11    Data Structure:Heap Sort_i++_08{
 9Data Structure:Heap Sort_其他_09        static void Main(string[] args)
10Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11        Data Structure:Heap Sort_i++_08{
11Data Structure:Heap Sort_其他_09            //arr[0]
12Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11            int[] arr = new int[] Data Structure:Heap Sort_i++_080,1,6,2,5,3,432,432,44,3,65,76,879,3,54,54543,33333333,33,2,4};
13Data Structure:Heap Sort_其他_09            HeapSort sort = new HeapSort(arr);
14Data Structure:Heap Sort_其他_09            sort.Sort();
15Data Structure:Heap Sort_其他_09            Console.ReadLine();
16Data Structure:Heap Sort_其他_24        }

17Data Structure:Heap Sort_其他_24    }

18Data Structure:Heap Sort_其他_09
19Data Structure:Heap Sort_其他_09    class HeapSort
20Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11    Data Structure:Heap Sort_i++_08{
21Data Structure:Heap Sort_其他_09        public int[] arr;
22Data Structure:Heap Sort_其他_09        public int length;
23Data Structure:Heap Sort_其他_09
24Data Structure:Heap Sort_其他_09        public HeapSort(int[] arr)
25Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11        Data Structure:Heap Sort_i++_08{
26Data Structure:Heap Sort_其他_09            this.arr = arr;
27Data Structure:Heap Sort_其他_09            this.length = this.arr.Length-1;
28Data Structure:Heap Sort_其他_24        }

29Data Structure:Heap Sort_其他_09
30Data Structure:Heap Sort_其他_09        public void HeapAdjust( int low, int high )
31Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11        Data Structure:Heap Sort_i++_08{
32Data Structure:Heap Sort_其他_09            int rc = arr[low];
33Data Structure:Heap Sort_其他_09
34Data Structure:Heap Sort_其他_09            for (int i = 2*low; i <= high; i *= 2)
35Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11            Data Structure:Heap Sort_i++_08{
36Data Structure:Heap Sort_其他_09                if (i<high && arr[i] < arr[i + 1]) i++;
37Data Structure:Heap Sort_其他_09                if (arr[i] < rc) break;
38Data Structure:Heap Sort_其他_09                arr[low] = arr[i]; 
39Data Structure:Heap Sort_其他_09                low = i; 
40Data Structure:Heap Sort_其他_24            }

41Data Structure:Heap Sort_其他_09
42Data Structure:Heap Sort_其他_09            arr[low] = rc;
43Data Structure:Heap Sort_其他_24        }

44Data Structure:Heap Sort_其他_09
45Data Structure:Heap Sort_其他_09        public void Sort()
46Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11        Data Structure:Heap Sort_i++_08{
47Data Structure:Heap Sort_其他_09            for (int i = length / 2; i >= 1; i--)
48Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11            Data Structure:Heap Sort_i++_08{
49Data Structure:Heap Sort_其他_09                HeapAdjust(i, length);
50Data Structure:Heap Sort_其他_24            }

51Data Structure:Heap Sort_其他_09
52Data Structure:Heap Sort_其他_09            for (int i = length; i > 1; i--)
53Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11            Data Structure:Heap Sort_i++_08
54Data Structure:Heap Sort_其他_09                int temp = arr[1];
55Data Structure:Heap Sort_其他_09                arr[1= arr[i];
56Data Structure:Heap Sort_其他_09                arr[i] = temp;
57Data Structure:Heap Sort_其他_09
58Data Structure:Heap Sort_其他_09                HeapAdjust(1, i - 1);
59Data Structure:Heap Sort_其他_24            }

60Data Structure:Heap Sort_其他_09
61Data Structure:Heap Sort_其他_09            for (int i = 1; i <= length; i++)
62Data Structure:Heap Sort_其他_10Data Structure:Heap Sort_i++_11            Data Structure:Heap Sort_i++_08{
63Data Structure:Heap Sort_其他_09                Console.Write(arr[i] + " ");
64Data Structure:Heap Sort_其他_24            }

65Data Structure:Heap Sort_其他_09            Console.WriteLine();
66Data Structure:Heap Sort_其他_24        }

67Data Structure:Heap Sort_其他_09
68Data Structure:Heap Sort_其他_24    }

69Data Structure:Heap Sort_i++_93}

70Data Structure:Heap Sort_i++