summaryrefslogtreecommitdiff
path: root/numsort.c
diff options
context:
space:
mode:
Diffstat (limited to 'numsort.c')
-rw-r--r--numsort.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/numsort.c b/numsort.c
index 36dbff6..a81e051 100644
--- a/numsort.c
+++ b/numsort.c
@@ -42,7 +42,7 @@ DoNumSort (void)
long* array = NULL;
clock_t total_time = 0;
int iterations = 0;
- static int num_arrays = 1;
+ static int num_arrays = 0;
static bool is_adjusted = false;
if (is_adjusted == false) {
@@ -54,7 +54,9 @@ DoNumSort (void)
** enough arrays are built to handle the tolerance.
*/
- while (1) {
+ do {
+ ++num_arrays;
+
array = realloc(array, num_arrays * ARRAY_SIZE * sizeof(long));
if (!array) {
fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
@@ -67,12 +69,7 @@ DoNumSort (void)
** minimum, then allocate for more arrays and
** try again.
*/
- if (DoNumSortIteration(array, num_arrays) > MINIMUM_TICKS) {
- break;
- }
-
- ++num_arrays;
- }
+ } while (DoNumSortIteration(array, num_arrays) <= MINIMUM_TICKS);
} else {
array = malloc(num_arrays * ARRAY_SIZE * sizeof(long));
if (!array) {