void integer_timsort(int array[], int size){ sort_state_struct state; state.storage = malloc(sizeof(int) * size); state.stack_height = 0; state.partitioned_up_to = array; state.array = array; state.length = size; while(next_partition(&state)){ while(should_collapse(&state)) merge_collapse(&state); } while(state.stack_height > 1) merge_collapse(&state); free(state.storage); }
void sort(int list[], int n) { Sort_stack stack; stack.storage = malloc(sizeof(int) * n); stack.stack_height = 0; stack.partitioned = list; stack.list = list; stack.length = n; while(partition(&stack)) { while(should_collapse(&stack)) { merge_collapse(&stack); } } while(stack.stack_height > 1) { merge_collapse(&stack); } free(stack.storage); }