-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/22 16:55:10 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/12 20:54:48 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/12 23:57:46 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -15,10 +15,21 @@ | |
#include "sort.h" | ||
#include "stack_operations.h" | ||
|
||
static void _push_b_n_times(t_stack **p_a, t_stack **p_b, int n) | ||
// 0...200: 1 | ||
// 200...300: 3 | ||
// 300...400: 5 | ||
// 400...500: 7 | ||
// 450...550: 5 | ||
// 550...650: 6 | ||
|
||
static int _calc_number_of_segments(int size_a) | ||
{ | ||
while (n--) | ||
operate_pb(p_a, p_b); | ||
int a; | ||
|
||
if (size_a <= 200) | ||
return (1); | ||
a = (size_a - 200) / 100; | ||
return (2 * a + 3); | ||
} | ||
|
||
static void _sort_stack_a(t_stack **p_a, int num_a) | ||
|
@@ -42,10 +53,7 @@ void large_sort(t_stack **p_a, t_stack **p_b) | |
|
||
size_a = stack_size(*p_a); | ||
size_b = size_a - 3; | ||
if (size_a < 200) | ||
_push_b_n_times(p_a, p_b, size_b); | ||
else | ||
push_b_segmented(p_a, p_b, size_b, 7); | ||
push_b_segmented(p_a, p_b, size_b, _calc_number_of_segments(size_a)); | ||
nano_sort(p_a); | ||
while (size_b--) | ||
{ | ||
|