-
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
9 changed files
with
56 additions
and
66 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/11 19:04:40 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/13 11:46:14 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/13 14:01:23 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -76,7 +76,7 @@ int *_coordinate_compression(int size_a, char **argv) | |
while (j < size_a) | ||
{ | ||
if (ft_atoi(argv[i + 1]) == sorted[j]) | ||
comp[i] = j + 1; | ||
comp[i] = j; | ||
j++; | ||
} | ||
i++; | ||
|
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/13 12:45:59 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/13 15:00:02 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -15,7 +15,7 @@ | |
#ifdef LEAK | ||
# ifdef __APPLE__ | ||
|
||
void leak_chek(void) __attribute__((destructor)); | ||
void leak_chek(void) __attribute__((destructor)); | ||
|
||
void leak_chek(void) | ||
{ | ||
|
@@ -33,6 +33,11 @@ void put_void(void *content) | |
|
||
#endif | ||
|
||
static void _put_void(void *p_content) | ||
{ | ||
ft_printf("%d\n", ((t_content *)p_content)->index); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
t_stack *st_a; | ||
|
@@ -41,6 +46,7 @@ int main(int argc, char **argv) | |
check_args(argc, argv); | ||
st_a = generate_stack(argc, argv); | ||
st_b = NULL; | ||
ft_lstiter(st_a, _put_void); | ||
sort(&st_a, &st_b); | ||
clear_stack(&st_a, free); | ||
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: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/10 18:47:11 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/11 12:54:04 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/13 14:01:58 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -17,7 +17,7 @@ bool is_sorted_stack(t_stack *st) | |
{ | ||
int current; | ||
|
||
current = 1; | ||
current = 0; | ||
while (st) | ||
{ | ||
if (get_content(st)->index != current) | ||
|
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,28 +6,14 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/11 22:57:28 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/12 23:28:29 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/13 15:01:23 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "large_sort.h" | ||
#include "push_swap.h" | ||
#include "stack_operations.h" | ||
|
||
// 1 ~ 100 | ||
// segment1: 1 ~ 20 | ||
// segment1: 21 ~ 40 | ||
// segment1: 41 ~ 60 | ||
// segment1: 61 ~ 80 | ||
// segment1: 81 ~ 100 | ||
|
||
// 123: 24 | ||
// [0, 24) -> [0, seg_size) | ||
// [24, 48) -> [seg_size, seg_size * 2) | ||
// [48, 72) -> [seg_size * 2, seg_size * 3) | ||
// [72, 96) -> [seg_size * 3, seg_size * 4) | ||
// [96, 123) -> [seg_size * 4, N) | ||
|
||
static int _calc_segment_id(int target, int n, int segs) | ||
{ | ||
int seg_size; | ||
|
@@ -48,8 +34,6 @@ static int _calc_segment_id(int target, int n, int segs) | |
return (-1); | ||
} | ||
|
||
// ft_printf("ns: %d, index: %d, pushed: %d, n: %d\n", num_segment, index, | ||
// pushed, n); | ||
static bool _should_push_b(int index, int pushed, int n, int segs) | ||
{ | ||
int seg_size; | ||
|
@@ -70,8 +54,8 @@ static bool _should_push_b(int index, int pushed, int n, int segs) | |
sup = seg_size * (cur_id + 1); | ||
} | ||
if (cur_id == segs - 1) | ||
return (inf < index && index <= n); | ||
return (inf < index && index <= sup); | ||
return (inf <= index); | ||
return (inf <= index && index < sup); | ||
} | ||
|
||
void push_b_segmented(t_stack **p_a, t_stack **p_b, int n, int segs) | ||
|
@@ -86,7 +70,7 @@ void push_b_segmented(t_stack **p_a, t_stack **p_b, int n, int segs) | |
if (_should_push_b(index, pushed, n, segs)) | ||
{ | ||
operate_pb(p_a, p_b); | ||
if (_calc_segment_id(index - 1, n, segs) % 2 == 1) | ||
if (_calc_segment_id(index, n, segs) % 2 == 1) | ||
operate_rb(p_b); | ||
pushed++; | ||
} | ||
|
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/11 12:54:02 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/13 15:38:56 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -18,21 +18,21 @@ static void _handle_4(t_stack **p_a, t_stack **p_b) | |
{ | ||
operate_pb(p_a, p_b); | ||
nano_sort(p_a); | ||
if (get_first_index(p_b) == 1) | ||
if (get_first_index(p_b) == 0) | ||
operate_pa(p_b, p_a); | ||
else if (get_first_index(p_b) == 2) | ||
else if (get_first_index(p_b) == 1) | ||
{ | ||
operate_pa(p_b, p_a); | ||
operate_sa(p_a); | ||
} | ||
else if (get_first_index(p_b) == 3) | ||
else if (get_first_index(p_b) == 2) | ||
{ | ||
operate_rra(p_a); | ||
operate_pa(p_b, p_a); | ||
operate_ra(p_a); | ||
operate_ra(p_a); | ||
} | ||
else if (get_first_index(p_b) == 4) | ||
else if (get_first_index(p_b) == 3) | ||
{ | ||
operate_pa(p_b, p_a); | ||
operate_ra(p_a); | ||
|
@@ -49,7 +49,7 @@ static void _edge_flow_5(t_stack **p_a, t_stack **p_b) | |
|
||
static void _normal_flow_5(t_stack **p_a, t_stack **p_b) | ||
{ | ||
if (get_first_index(p_b) == 5) | ||
if (get_first_index(p_b) == 4) | ||
{ | ||
operate_pa(p_b, p_a); | ||
operate_rra(p_a); | ||
|
@@ -63,7 +63,7 @@ static void _normal_flow_5(t_stack **p_a, t_stack **p_b) | |
while (get_first_index(p_a) != get_first_index(p_b) + 1) | ||
operate_rra(p_a); | ||
operate_pa(p_b, p_a); | ||
while (get_first_index(p_a) != 1) | ||
while (get_first_index(p_a) != 0) | ||
operate_rra(p_a); | ||
} | ||
|
||
|
@@ -74,7 +74,7 @@ static void _handle_5(t_stack **p_a, t_stack **p_b) | |
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) | ||
if (get_first_index(p_b) == 4 && get_second_index(p_b) == 3) | ||
_edge_flow_5(p_a, p_b); | ||
else | ||
_normal_flow_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
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