-
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
137 additions
and
3 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/01/17 18:29:53 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/22 16:55:46 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -30,6 +30,7 @@ t_list *generate_stack(int argc, char **argv); | |
void sort(t_list **stack_a, t_list **stack_b, int num_a); | ||
void nano_sort(t_list **stack, int num_a); | ||
void micro_sort(t_list **stack_a, t_list **stack_b, int num_a); | ||
void large_sort(t_list **stack_a, t_list **stack_b, int num_a); | ||
|
||
void operate_sa(t_list **stack_a); | ||
void operate_sb(t_list **stack_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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* large_sort.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/22 16:55:10 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/22 17:02:49 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
|
||
// naive implement: insertion sort | ||
// find smallest number of a | ||
// rotate | ||
// push to stack_b | ||
// push to stack_a | ||
|
||
static void push_in_order(t_list **stack_a, t_list **stack_b, int num_a) | ||
{ | ||
int i; | ||
|
||
i = 1; | ||
while (i <= num_a) | ||
{ | ||
if (first_content(stack_a) == i) | ||
{ | ||
operate_pb(stack_a, stack_b); | ||
i++; | ||
} | ||
else | ||
operate_ra(stack_a); | ||
} | ||
} | ||
|
||
static void push_revert(t_list **stack_a, t_list **stack_b, int num_a) | ||
{ | ||
int i; | ||
|
||
i = 0; | ||
while (i < num_a) | ||
{ | ||
operate_pa(stack_b, stack_a); | ||
i++; | ||
} | ||
} | ||
|
||
void large_sort(t_list **stack_a, t_list **stack_b, int num_a) | ||
{ | ||
push_in_order(stack_a, stack_b, num_a); | ||
push_revert(stack_a, stack_b, num_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,7 +6,7 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/15 15:10:35 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/17 16:08:05 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/22 16:54:56 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -18,4 +18,6 @@ void sort(t_list **stack_a, t_list **stack_b, int num_a) | |
nano_sort(stack_a, num_a); | ||
else if (num_a <= 5) | ||
micro_sort(stack_a, stack_b, num_a); | ||
else | ||
large_sort(stack_a, stack_b, num_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