File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
source/code/projects/Sorting/Sorting Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ public static bool IsSorted(List<T> listP)
2424 }
2525 return isSorted ;
2626 }
27+
2728 // Done with helpers method.
2829
2930 // Insertion Algorithm
@@ -53,21 +54,22 @@ private static int LeftChild(int i)
5354 {
5455 return 2 * i + 1 ;
5556 }
56- // Done with helper method for Heapsort
57+
58+ // Done with helper method for Heapsort
5759
5860 // Heapsort algorithm
5961 public static void Heapsort ( List < T > listP )
6062 {
61- // Step 1: heapify, or build heap.
62- for ( int i = listP . Count / 2 ; i >= 0 ; i -- )
63- PercDown ( listP , i , listP . Count ) ;
64- // Step 2: recursively extract the largest value.
65- for ( int i = listP . Count - 1 ; i > 0 ; i -- )
66- {
67- Swap ( listP , 0 , i ) ;
68- PercDown ( listP , 0 , i ) ;
69- }
63+ // Step 1: heapify, or build heap.
64+ for ( int i = listP . Count / 2 ; i >= 0 ; i -- )
65+ PercDown ( listP , i , listP . Count ) ;
66+ // Step 2: recursively extract the largest value.
67+ for ( int i = listP . Count - 1 ; i > 0 ; i -- )
68+ {
69+ Swap ( listP , 0 , i ) ;
70+ PercDown ( listP , 0 , i ) ;
7071 }
72+ }
7173
7274 private static void PercDown ( List < T > listP , int i , int N )
7375 {
You can’t perform that action at this time.
0 commit comments