-
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.
* add check.rb * optimzie micro sort * refactor first / second content * refacotr _handle_5 with 2 flows
- Loading branch information
Showing
6 changed files
with
86 additions
and
26 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 16:22:03 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/17 18:29:53 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -43,6 +43,8 @@ void rotate_stack(t_list **stack); | |
void reverse_rotate_stack(t_list **stack); | ||
t_list *ft_lst_before(t_list *lst, t_list *trg); | ||
|
||
int first_content(t_list **stack); | ||
int second_content(t_list **stack); | ||
void exit_with_error(void); | ||
|
||
#endif |
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,72 +6,78 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/15 16:32:27 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/17 17:43:30 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/17 18:33:18 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
|
||
static int _first(t_list **stack) | ||
{ | ||
return (*(int *)(*stack)->content); | ||
} | ||
|
||
static int _second(t_list **stack) | ||
{ | ||
return (*(int *)(*stack)->next->content); | ||
} | ||
|
||
static void _handle_4(t_list **stack_a, t_list **stack_b) | ||
{ | ||
operate_pb(stack_a, stack_b); | ||
nano_sort(stack_a, 3); | ||
if (_first(stack_b) == 1) | ||
if (first_content(stack_b) == 1) | ||
operate_pa(stack_b, stack_a); | ||
else if (_first(stack_b) == 2) | ||
else if (first_content(stack_b) == 2) | ||
{ | ||
operate_pa(stack_b, stack_a); | ||
operate_sa(stack_a); | ||
} | ||
else if (_first(stack_b) == 3) | ||
else if (first_content(stack_b) == 3) | ||
{ | ||
operate_rra(stack_a); | ||
operate_pa(stack_b, stack_a); | ||
operate_ra(stack_a); | ||
operate_ra(stack_a); | ||
} | ||
else if (_first(stack_b) == 4) | ||
else if (first_content(stack_b) == 4) | ||
{ | ||
operate_pa(stack_b, stack_a); | ||
operate_ra(stack_a); | ||
} | ||
} | ||
|
||
static void _handle_5(t_list **stack_a, t_list **stack_b) | ||
static void _edge_flow_5(t_list **stack_a, t_list **stack_b) | ||
{ | ||
operate_pb(stack_a, stack_b); | ||
operate_pb(stack_a, stack_b); | ||
nano_sort(stack_a, 3); | ||
if (_first(stack_b) < _second(stack_b)) | ||
operate_sb(stack_b); | ||
if (_first(stack_b) == 5) | ||
operate_pa(stack_b, stack_a); | ||
operate_pa(stack_b, stack_a); | ||
operate_ra(stack_a); | ||
operate_ra(stack_a); | ||
} | ||
|
||
static void _normal_flow_5(t_list **stack_a, t_list **stack_b) | ||
{ | ||
if (first_content(stack_b) == 5) | ||
{ | ||
operate_pa(stack_b, stack_a); | ||
operate_rra(stack_a); | ||
} | ||
else | ||
{ | ||
while (_first(stack_a) != _first(stack_b) + 1) | ||
while (first_content(stack_a) != first_content(stack_b) + 1) | ||
operate_ra(stack_a); | ||
operate_pa(stack_b, stack_a); | ||
} | ||
while (_first(stack_a) != _first(stack_b) + 1) | ||
while (first_content(stack_a) != first_content(stack_b) + 1) | ||
operate_rra(stack_a); | ||
operate_pa(stack_b, stack_a); | ||
while (_first(stack_a) != 1) | ||
while (first_content(stack_a) != 1) | ||
operate_rra(stack_a); | ||
} | ||
|
||
static void _handle_5(t_list **stack_a, t_list **stack_b) | ||
{ | ||
operate_pb(stack_a, stack_b); | ||
operate_pb(stack_a, stack_b); | ||
nano_sort(stack_a, 3); | ||
if (first_content(stack_b) < second_content(stack_b)) | ||
operate_sb(stack_b); | ||
if (first_content(stack_b) == 5 && second_content(stack_b) == 4) | ||
_edge_flow_5(stack_a, stack_b); | ||
else | ||
_normal_flow_5(stack_a, stack_b); | ||
} | ||
|
||
void micro_sort(t_list **stack_a, t_list **stack_b, int num_a) | ||
{ | ||
if (num_a == 4) | ||
|
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,18 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* first_content.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/17 18:27:37 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/17 18:29:06 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
|
||
int first_content(t_list **stack) | ||
{ | ||
return (*(int *)(*stack)->content); | ||
} |
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,18 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* second_content.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/17 18:28:02 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/17 18:29:17 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
|
||
int second_content(t_list **stack) | ||
{ | ||
return (*(int *)(*stack)->next->content); | ||
} |
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
a = [1, 2, 3, 4, 5] | ||
|
||
a.permutation.to_a.each do |array| | ||
str = +'./push_swap' | ||
array.each do |item| | ||
str << " #{item}" | ||
end | ||
str << ' | wc -l | bc' | ||
puts str | ||
system str, exception: true | ||
puts "\n" | ||
end |