-
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
5 changed files
with
32 additions
and
24 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: lgaudin <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/08 14:58:28 by lgaudin #+# #+# */ | ||
/* Updated: 2023/06/08 18:12:26 by lgaudin ### ########.fr */ | ||
/* Updated: 2023/06/10 15:08:32 by lgaudin ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -81,7 +81,7 @@ int main(int argc, char *argv[]) | |
arguments = argv + 1; | ||
a = populate_stack(arguments, argc); | ||
if (get_array_length(arguments) == 1 || already_sorted(a) == 1) | ||
exit_without_error(a, NULL, arguments); | ||
exit_without_error(a, NULL, arguments, argc); | ||
if (!a) | ||
print_error(a, arguments, argc); | ||
b = initialise_stack(); | ||
|
@@ -90,6 +90,6 @@ int main(int argc, char *argv[]) | |
ft_printf("OK\n"); | ||
else | ||
ft_printf("KO\n"); | ||
exit_without_error(a, b, arguments); | ||
exit_without_error(a, b, arguments, argc); | ||
return (0); | ||
} |
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: lgaudin <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/04 11:58:46 by lgaudin #+# #+# */ | ||
/* Updated: 2023/06/08 17:04:41 by lgaudin ### ########.fr */ | ||
/* Updated: 2023/06/10 15:05:37 by lgaudin ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -26,11 +26,13 @@ int main(int argc, char *argv[]) | |
arguments = argv + 1; | ||
a = populate_stack(arguments, argc); | ||
if (get_array_length(arguments) == 1 || already_sorted(a) == 1) | ||
exit_without_error(a, NULL, arguments); | ||
exit_without_error(a, NULL, arguments, argc); | ||
if (!a) | ||
print_error(a, arguments, argc); | ||
b = initialise_stack(); | ||
sort_stack(a, b, arguments); | ||
exit_without_error(a, b, arguments); | ||
sort_stack(a, b, arguments, argc); | ||
if (argc == 2) | ||
free_arguments(arguments); | ||
exit_without_error(a, b, arguments, argc); | ||
return (0); | ||
} |
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: lgaudin <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/04 16:45:55 by lgaudin #+# #+# */ | ||
/* Updated: 2023/06/07 16:25:20 by lgaudin ### ########.fr */ | ||
/* Updated: 2023/06/10 15:04:48 by lgaudin ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -102,9 +102,11 @@ int already_sorted(t_stack *stack) | |
* @param stack_b | ||
* @param arguments | ||
*/ | ||
void exit_without_error(t_stack *stack_a, t_stack *stack_b, char **arguments) | ||
void exit_without_error(t_stack *stack_a, t_stack *stack_b, char **arguments, | ||
int argc) | ||
{ | ||
free_arguments(arguments); | ||
if (argc == 2) | ||
free_arguments(arguments); | ||
free_stack(stack_a); | ||
free_stack(stack_b); | ||
exit(0); | ||
|
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: lgaudin <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/04 15:48:14 by lgaudin #+# #+# */ | ||
/* Updated: 2023/06/08 15:04:22 by lgaudin ### ########.fr */ | ||
/* Updated: 2023/06/10 15:05:19 by lgaudin ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -109,14 +109,17 @@ static void big_sort(t_stack *stack_a, t_stack *stack_b, int chunk_count) | |
* @param stack_a Stack to sort. | ||
* @param stack_b Stack to use as a buffer. | ||
*/ | ||
void sort_stack(t_stack *stack_a, t_stack *stack_b, char **arguments) | ||
void sort_stack(t_stack *stack_a, t_stack *stack_b, char **arguments, | ||
int argc) | ||
{ | ||
if (already_sorted(stack_a)) | ||
exit_without_error(stack_a, stack_b, arguments); | ||
else if (stack_a->size <= 6) | ||
small_sort(stack_a, stack_b); | ||
else if (stack_a->size <= 100) | ||
big_sort(stack_a, stack_b, 5); | ||
else | ||
big_sort(stack_a, stack_b, 11); | ||
if (already_sorted(stack_a) == 0) | ||
{ | ||
if (stack_a->size <= 6) | ||
small_sort(stack_a, stack_b); | ||
else if (stack_a->size <= 100) | ||
big_sort(stack_a, stack_b, 5); | ||
else | ||
big_sort(stack_a, stack_b, 11); | ||
} | ||
exit_without_error(stack_a, stack_b, arguments, argc); | ||
} |
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: lgaudin <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/04 13:32:24 by lgaudin #+# #+# */ | ||
/* Updated: 2023/06/08 17:04:30 by lgaudin ### ########.fr */ | ||
/* Updated: 2023/06/10 15:04:41 by lgaudin ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -31,7 +31,8 @@ void push(t_stack *src, t_stack *dest); | |
void rotate(t_stack *stack); | ||
void reverse_rotate(t_stack *stack); | ||
void swap(t_stack *stack); | ||
void sort_stack(t_stack *stack_a, t_stack *stack_b, char **arguments); | ||
void sort_stack(t_stack *stack_a, t_stack *stack_b, char **arguments, | ||
int argc); | ||
void ss(t_stack *stack_a, t_stack *stack_b, int print); | ||
void sa(t_stack *stack_a, int print); | ||
void sb(t_stack *stack_b, int print); | ||
|
@@ -63,7 +64,7 @@ int is_biggest_or_smallest(t_stack *stack, int value); | |
void move_in_range_to_top(t_stack *stack, int min, int max, char stack_name); | ||
int get_directly_below_index(t_stack *stack, int value); | ||
int get_directly_above_index(t_stack *stack, int value); | ||
void exit_without_error(t_stack *stack_a, t_stack *stack_b, | ||
char **arguments); | ||
void exit_without_error(t_stack *stack_a, t_stack *stack_b, char **arguments, | ||
int argc); | ||
|
||
#endif |