-
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
11 changed files
with
53 additions
and
47 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
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/10 12:37:54 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 21:12:16 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/10 21:18:02 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -46,10 +46,10 @@ int check_args(int argc, char **argv); | |
t_stack *generate_stack(int argc, char **argv); | ||
void exit_with_error(void); | ||
|
||
void sort(t_stack **p_a, t_stack **p_b, int num_a); | ||
void nano_sort(t_stack **p_a, int num_a); | ||
void micro_sort(t_stack **p_a, t_stack **p_b, int num_a); | ||
void large_sort(t_stack **p_a, t_stack **p_b, int num_a); | ||
void sort(t_stack **p_a, t_stack **p_b); | ||
void nano_sort(t_stack **p_a); | ||
void micro_sort(t_stack **p_a, t_stack **p_b); | ||
void large_sort(t_stack **p_a, t_stack **p_b); | ||
void set_cost(t_stack **p_a, t_stack **p_b); | ||
void set_opt(t_stack **p_b); | ||
void greedy_operation(t_stack **p_a, t_stack **p_b); | ||
|
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/10 12:37:36 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/07 15:12:35 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/10 21:19:08 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -41,7 +41,7 @@ int main(int argc, char **argv) | |
check_args(argc, argv); | ||
a = generate_stack(argc, argv); | ||
b = NULL; | ||
sort(&a, &b, argc - 1); | ||
sort(&a, &b); | ||
clear_stack(&a, free); | ||
return (0); | ||
} |
File renamed without changes.
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,22 +6,16 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/22 16:55:10 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 19:31:10 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/10 21:24:58 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
|
||
static void _init_stack(t_stack **p_a, t_stack **p_b, int num_a) | ||
static void _push_b_n_times(t_stack **p_a, t_stack **p_b, int n) | ||
{ | ||
int i; | ||
|
||
i = 0; | ||
while (i < num_a - 3) | ||
{ | ||
while (n--) | ||
operate_pb(p_a, p_b); | ||
i++; | ||
} | ||
} | ||
|
||
static void _sort_stack_a(t_stack **p_a, int num_a) | ||
|
@@ -38,19 +32,20 @@ static void _sort_stack_a(t_stack **p_a, int num_a) | |
} | ||
} | ||
|
||
void large_sort(t_stack **p_a, t_stack **p_b, int num_a) | ||
void large_sort(t_stack **p_a, t_stack **p_b) | ||
{ | ||
int i; | ||
int size_a; | ||
int size_b; | ||
|
||
_init_stack(p_a, p_b, num_a); | ||
nano_sort(p_a, 3); | ||
i = 0; | ||
while (i < num_a - 3) | ||
size_a = stack_size(*p_a); | ||
size_b = size_a - 3; | ||
_push_b_n_times(p_a, p_b, size_b); | ||
nano_sort(p_a); | ||
while (size_b--) | ||
{ | ||
set_cost(p_a, p_b); | ||
set_opt(p_b); | ||
greedy_operation(p_a, p_b); | ||
i++; | ||
} | ||
_sort_stack_a(p_a, num_a); | ||
_sort_stack_a(p_a, size_a); | ||
} |
File renamed without changes.
File renamed without changes.
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/15 16:32:27 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 20:55:11 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/10 21:17:40 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -15,7 +15,7 @@ | |
static void _handle_4(t_stack **p_a, t_stack **p_b) | ||
{ | ||
operate_pb(p_a, p_b); | ||
nano_sort(p_a, 3); | ||
nano_sort(p_a); | ||
if (get_first_index(p_b) == 1) | ||
operate_pa(p_b, p_a); | ||
else if (get_first_index(p_b) == 2) | ||
|
@@ -69,7 +69,7 @@ static void _handle_5(t_stack **p_a, t_stack **p_b) | |
{ | ||
operate_pb(p_a, p_b); | ||
operate_pb(p_a, p_b); | ||
nano_sort(p_a, 3); | ||
nano_sort(p_a); | ||
if (get_first_index(p_b) < get_second_index(p_b)) | ||
operate_sb(p_b); | ||
if (get_first_index(p_b) == 5 && get_second_index(p_b) == 4) | ||
|
@@ -78,10 +78,13 @@ static void _handle_5(t_stack **p_a, t_stack **p_b) | |
_normal_flow_5(p_a, p_b); | ||
} | ||
|
||
void micro_sort(t_stack **p_a, t_stack **p_b, int num_a) | ||
void micro_sort(t_stack **p_a, t_stack **p_b) | ||
{ | ||
if (num_a == 4) | ||
int size_a; | ||
|
||
size_a = stack_size(*p_a); | ||
if (size_a == 4) | ||
_handle_4(p_a, p_b); | ||
else if (num_a == 5) | ||
else if (size_a == 5) | ||
_handle_5(p_a, p_b); | ||
} |
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/12 15:58:22 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/10 20:56:41 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/10 21:14:43 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -48,10 +48,13 @@ static void _handle_3(t_stack **p_a) | |
operate_rra(p_a); | ||
} | ||
|
||
void nano_sort(t_stack **p_a, int num_a) | ||
void nano_sort(t_stack **p_a) | ||
{ | ||
if (num_a == 2) | ||
int size_a; | ||
|
||
size_a = stack_size(*p_a); | ||
if (size_a == 2) | ||
_handle_2(p_a); | ||
else if (num_a == 3) | ||
else if (size_a == 3) | ||
_handle_3(p_a); | ||
} |
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,18 +6,23 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/15 15:10:35 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/07 16:35:12 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/10 21:36:16 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
|
||
void sort(t_stack **p_a, t_stack **p_b, int num_a) | ||
void sort(t_stack **p_a, t_stack **p_b) | ||
{ | ||
if (num_a <= 3) | ||
nano_sort(p_a, num_a); | ||
else if (num_a <= 5) | ||
micro_sort(p_a, p_b, num_a); | ||
int size_a; | ||
|
||
if (is_sorted_stack(*p_a)) | ||
return ; | ||
size_a = stack_size(*p_a); | ||
if (size_a <= 3) | ||
nano_sort(p_a); | ||
else if (size_a <= 5) | ||
micro_sort(p_a, p_b); | ||
else | ||
large_sort(p_a, p_b, num_a); | ||
large_sort(p_a, p_b); | ||
} |
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