99
1010namespace HeapSort {
1111
12- void GetHeapifyCount (Rectangle* array, int size, int index, int stepCount) {
12+ void GetHeapifyCount (Rectangle* array, int size, int index, int * stepCount) {
1313 int largest = index;
1414
1515 // IF LEFT CHILD IS LARGER, SET AS LARGEST
@@ -29,7 +29,7 @@ namespace HeapSort {
2929 Swap (array, index, largest);
3030
3131 // INCREMENT STEP COUNTER
32- stepCount++;
32+ (* stepCount) ++;
3333
3434 // RECURSIVELY HEAPIFY THE AFFECTED SUB-TREE
3535 GetHeapifyCount (array, size, largest, stepCount);
@@ -39,7 +39,7 @@ namespace HeapSort {
3939 int GetStepCount (Rectangle* items) {
4040 Rectangle* array = CopyArray (items);
4141
42- int stepCount = 0 ;
42+ int * stepCount = ( int *) calloc ( 1 , sizeof ( int )) ;
4343
4444 // BUILD INITIAL HEAP
4545 for (int i = LIST_SIZE / 2 - 1 ; i >= 0 ; i--) {
@@ -52,20 +52,21 @@ namespace HeapSort {
5252 Swap (array, 0 , i);
5353
5454 // INCREMENT THE STEP COUNTER
55- stepCount++;
55+ (* stepCount) ++;
5656
5757 // CALL HEAPIFY ON THE REDUCED SIZE HEAP
5858 GetHeapifyCount (array, i, 0 , stepCount);
5959 }
6060
6161 // INCREMENT FOR FINAL STEP
62- stepCount++;
62+ (* stepCount) ++;
6363
6464 free (array);
65- return stepCount;
65+ int test = stepCount[0 ];
66+ return stepCount[0 ];
6667 }
6768
68- void Heapify (Rectangle* array, int size, int index, int currentStep, SortSequence sort) {
69+ void Heapify (Rectangle* array, int size, int index, int * currentStep, SortSequence sort) {
6970 int largest = index;
7071
7172 // IF LEFT CHILD IS LARGER, SET AS LARGEST
@@ -87,15 +88,14 @@ namespace HeapSort {
8788 // RECORD THE SORTING STEP (SNAPSHOT OF THE ARRAY)
8889 int offset;
8990 for (int i = 0 ; i < LIST_SIZE; i++) {
90- offset = (currentStep * LIST_SIZE) + i;
91+ offset = ((* currentStep) * LIST_SIZE) + i;
9192 sort.steps [offset].value = array[i].value ;
92- sort.steps [offset].rect_color = rect_base_color;
93-
94- // TODO: ADD COLOR FOR HEAP SORT
95- // bool isOrdered = i >= (LIST_SIZE - index);
96- // sort.steps[offset].rect_color = GetRectangleColor(isOrdered, false, false);
93+
94+ // SET RECTANGLE COLOR VALUE
95+ bool isOrdered = i >= size;
96+ sort.steps [offset].rect_color = GetRectangleColor (isOrdered, false , false );
9797 }
98- currentStep++;
98+ (* currentStep) ++;
9999
100100 // RECURSIVELY HEAPIFY THE AFFECTED SUB-TREE
101101 Heapify (array, size, largest, currentStep, sort);
@@ -112,7 +112,7 @@ namespace HeapSort {
112112 sort.steps = (SortStep*) malloc (LIST_SIZE * stepCount * sizeof (SortStep));
113113
114114 int offset;
115- int currentStep = 0 ;
115+ int * currentStep = ( int *) calloc ( 1 , sizeof ( int )) ;
116116
117117 // BUILD INITIAL HEAP
118118 for (int index = LIST_SIZE / 2 - 1 ; index >= 0 ; index--) {
@@ -126,28 +126,24 @@ namespace HeapSort {
126126
127127 // RECORD THE SORTING STEP (SNAPSHOT OF THE ARRAY)
128128 for (int i = 0 ; i < LIST_SIZE; i++) {
129- offset = (currentStep * LIST_SIZE) + i;
129+ offset = (currentStep[ 0 ] * LIST_SIZE) + i;
130130 sort.steps [offset].value = array[i].value ;
131- sort.steps [offset].rect_color = rect_base_color;
132131
133- // TODO: ADD COLOR FOR HEAP SORT
134- // bool isOrdered = i >= (LIST_SIZE - index) ;
135- // sort.steps[offset].rect_color = GetRectangleColor(isOrdered, false, false);
132+ // SET RECTANGLE COLOR VALUE
133+ bool isOrdered = i >= index;
134+ sort.steps [offset].rect_color = GetRectangleColor (isOrdered, false , false );
136135 }
137- currentStep++;
136+ (* currentStep) ++;
138137
139138 // CALL HEAPIFY ON THE REDUCED SIZE HEAP
140139 Heapify (array, index, 0 , currentStep, sort);
141140 }
142141
143142 // RECORD FINAL STEP (ORDERED LIST)
144143 for (int i = 0 ; i < LIST_SIZE; i++) {
145- offset = (currentStep * LIST_SIZE) + i;
144+ offset = (currentStep[ 0 ] * LIST_SIZE) + i;
146145 sort.steps [offset].value = array[i].value ;
147- sort.steps [offset].rect_color = rect_base_color;
148-
149- // TODO: ADD COLOR FOR HEAP SORT
150- // sort.steps[offset].rect_color = rect_green_color;
146+ sort.steps [offset].rect_color = rect_green_color;
151147 }
152148
153149 free (array);
0 commit comments