-
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
6 changed files
with
38 additions
and
65 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/08 07:44:33 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/08 13:35:51 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -38,8 +38,7 @@ 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 set_selection_cost(t_stack **p_b); | ||
void set_insertion_cost(t_stack **p_a, t_stack **p_b); | ||
void set_cost(t_stack **p_a, t_stack **p_b); | ||
|
||
void operate_sa(t_stack **p_a); | ||
void operate_sb(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/22 16:55:10 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/08 07:33:42 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/08 13:34:33 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -28,6 +28,5 @@ void large_sort(t_stack **p_a, t_stack **p_b, int num_a) | |
{ | ||
_init_stack(p_a, p_b, num_a); | ||
nano_sort(p_a, 3); | ||
set_selection_cost(p_b); | ||
set_insertion_cost(p_a, p_b); | ||
set_cost(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 |
---|---|---|
@@ -1,80 +1,85 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* set_insertion_cost.c :+: :+: :+: */ | ||
/* set_cost.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/08 07:32:05 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/08 10:09:34 by reasuke ### ########.fr */ | ||
/* Created: 2024/02/08 12:17:33 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/08 21:38:17 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
|
||
static void _set_insertion_forward_cost(t_stack **p_a, t_stack *st_b) | ||
static int _calc_insertion_threshold(t_stack **p_a, t_stack *st_b) | ||
{ | ||
t_stack *st_a; | ||
int size_a; | ||
int i; | ||
int threshold; | ||
int max_a; | ||
int max_index; | ||
int min; | ||
|
||
st_a = *p_a; | ||
size_a = stack_size(*p_a); | ||
i = 0; | ||
threshold = INT_MAX; | ||
min = INT_MAX; | ||
max_a = INT_MIN; | ||
while (i < size_a) | ||
{ | ||
if (get_content(st_a)->index > get_content(st_b)->index | ||
&& ft_chmin(&min, get_content(st_a)->index)) | ||
threshold = i; | ||
if (ft_chmax(&max_a, get_content(st_a)->index)) | ||
max_index = i; | ||
st_a = st_a->next; | ||
i++; | ||
} | ||
if (threshold == INT_MAX) | ||
threshold = (max_index + 1) % size_a; | ||
get_content(st_b)->if_cost = threshold % size_a; | ||
return (threshold); | ||
} | ||
|
||
static void _set_insertion_reverse_cost(t_stack **p_a, t_stack *st_b) | ||
static int _calc_max_index(t_stack **p_a) | ||
{ | ||
t_stack *st_a; | ||
int size_a; | ||
int i; | ||
int threshold; | ||
int max_a; | ||
int max_index; | ||
int min; | ||
|
||
st_a = *p_a; | ||
size_a = stack_size(*p_a); | ||
i = 0; | ||
threshold = INT_MAX; | ||
min = INT_MAX; | ||
max_a = INT_MIN; | ||
while (i < size_a) | ||
{ | ||
if (get_content(st_a)->index > get_content(st_b)->index | ||
&& ft_chmin(&min, get_content(st_a)->index)) | ||
threshold = i; | ||
if (ft_chmax(&max_a, get_content(st_a)->index)) | ||
max_index = i; | ||
st_a = st_a->next; | ||
i++; | ||
} | ||
return (max_index); | ||
} | ||
|
||
static void _set_insertion_cost(t_stack **p_a, t_stack *st_b) | ||
{ | ||
int max_index; | ||
int size_a; | ||
int threshold; | ||
|
||
size_a = stack_size(*p_a); | ||
threshold = _calc_insertion_threshold(p_a, st_b); | ||
max_index = _calc_max_index(p_a); | ||
if (threshold == INT_MAX) | ||
threshold = (max_index + 1) % size_a; | ||
get_content(st_b)->if_cost = threshold % size_a; | ||
get_content(st_b)->ir_cost = -((size_a - threshold) % size_a); | ||
} | ||
|
||
void set_insertion_cost(t_stack **p_a, t_stack **p_b) | ||
static void _set_selection_cost(t_stack *st_b, int i, int size_b) | ||
{ | ||
get_content(st_b)->sf_cost = i; | ||
get_content(st_b)->sr_cost = -((size_b - i) % size_b); | ||
} | ||
|
||
void set_cost(t_stack **p_a, t_stack **p_b) | ||
{ | ||
t_stack *st_b; | ||
int size_b; | ||
|
@@ -85,8 +90,8 @@ void set_insertion_cost(t_stack **p_a, t_stack **p_b) | |
i = 0; | ||
while (i < size_b) | ||
{ | ||
_set_insertion_forward_cost(p_a, st_b); | ||
_set_insertion_reverse_cost(p_a, st_b); | ||
_set_selection_cost(st_b, i, size_b); | ||
_set_insertion_cost(p_a, st_b); | ||
st_b = st_b->next; | ||
i++; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
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