-
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
8 changed files
with
57 additions
and
50 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/15 16:31:59 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/15 16:58:32 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -34,6 +34,8 @@ void micro_sort(t_list **stack_a, t_list **stack_b); | |
void operate_sa(t_list **stack_a); | ||
void operate_ra(t_list **stack_a); | ||
void operate_rra(t_list **stack_a); | ||
void operate_pa(t_list **stack_b, t_list **stack_a); | ||
void operate_pb(t_list **stack_a, t_list **stack_b); | ||
void push_stack(t_list **stack_1, t_list **stack_2); | ||
void swap_stack(t_list **stack); | ||
void rotate_stack(t_list **stack); | ||
|
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/01/15 16:34:16 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/15 16:59:58 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -39,9 +39,7 @@ int main(int argc, char **argv) | |
check_args(argc, argv); | ||
stack_a = generate_stack(argc, argv); | ||
stack_b = NULL; | ||
ft_lstiter(stack_a, put_void); | ||
sort(&stack_a, &stack_b, argc); | ||
ft_lstiter(stack_a, put_void); | ||
ft_lstclear(&stack_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/01/15 16:32:27 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/15 16:52:45 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/15 16:59:03 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -21,28 +21,22 @@ void micro_sort(t_list **stack_a, t_list **stack_b) | |
tmp = *(int *)(*stack_b)->content; | ||
nano_sort(stack_a, 3); | ||
if (tmp == 1) | ||
{ | ||
push_stack(stack_b, stack_a); | ||
ft_putendl_fd("pa", STDOUT_FILENO); | ||
} | ||
operate_pa(stack_b, stack_a); | ||
if (tmp == 2) | ||
{ | ||
push_stack(stack_b, stack_a); | ||
ft_putendl_fd("pa", STDOUT_FILENO); | ||
operate_pa(stack_b, stack_a); | ||
operate_sa(stack_a); | ||
} | ||
else if (tmp == 3) | ||
{ | ||
operate_rra(stack_a); | ||
push_stack(stack_b, stack_a); | ||
ft_putendl_fd("pa", STDOUT_FILENO); | ||
operate_pa(stack_b, stack_a); | ||
operate_ra(stack_a); | ||
operate_ra(stack_a); | ||
} | ||
else if (tmp == 4) | ||
{ | ||
push_stack(stack_b, stack_a); | ||
ft_putendl_fd("pa", STDOUT_FILENO); | ||
operate_pa(stack_b, stack_a); | ||
operate_ra(stack_a); | ||
} | ||
} |
30 changes: 13 additions & 17 deletions
30
src/stack_operations/operation.c → src/stack_operations/ft_lst_before.c
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,31 +1,27 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* operation.c :+: :+: :+: */ | ||
/* ft_lst_before.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/15 15:32:19 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/15 16:48:46 by reasuke ### ########.fr */ | ||
/* Created: 2024/01/15 16:54:29 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/15 16:54:44 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "push_swap.h" | ||
|
||
void operate_sa(t_list **stack_a) | ||
t_list *ft_lst_before(t_list *lst, t_list *trg) | ||
{ | ||
swap_stack(stack_a); | ||
ft_putendl_fd("sa", STDOUT_FILENO); | ||
} | ||
t_list *before; | ||
|
||
void operate_ra(t_list **stack_a) | ||
{ | ||
rotate_stack(stack_a); | ||
ft_putendl_fd("ra", STDOUT_FILENO); | ||
} | ||
|
||
void operate_rra(t_list **stack_a) | ||
{ | ||
reverse_rotate_stack(stack_a); | ||
ft_putendl_fd("rra", STDOUT_FILENO); | ||
if (!lst) | ||
return (NULL); | ||
before = lst; | ||
while (before->next && before->next != trg) | ||
before = before->next; | ||
if (before->next != trg) | ||
return (NULL); | ||
return (before); | ||
} |
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:56:53 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/15 16:15:33 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/15 16:57:43 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -23,3 +23,16 @@ void push_stack(t_list **stack_1, t_list **stack_2) | |
stack_1_first->next = NULL; | ||
ft_lstadd_front(stack_2, stack_1_first); | ||
} | ||
|
||
void operate_pa(t_list **stack_b, t_list **stack_a) | ||
{ | ||
push_stack(stack_b, stack_a); | ||
ft_putendl_fd("pa", STDOUT_FILENO); | ||
} | ||
|
||
void operate_pb(t_list **stack_a, t_list **stack_b) | ||
{ | ||
push_stack(stack_a, stack_b); | ||
ft_putendl_fd("pb", STDOUT_FILENO); | ||
} | ||
|
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 14:05:46 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/15 15:17:24 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/15 16:56:39 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -26,20 +26,6 @@ void rotate_stack(t_list **stack) | |
*stack = second; | ||
} | ||
|
||
t_list *ft_lst_before(t_list *lst, t_list *trg) | ||
{ | ||
t_list *before; | ||
|
||
if (!lst) | ||
return (NULL); | ||
before = lst; | ||
while (before->next && before->next != trg) | ||
before = before->next; | ||
if (before->next != trg) | ||
return (NULL); | ||
return (before); | ||
} | ||
|
||
void reverse_rotate_stack(t_list **stack) | ||
{ | ||
t_list *before_last; | ||
|
@@ -53,3 +39,15 @@ void reverse_rotate_stack(t_list **stack) | |
last->next = *stack; | ||
*stack = last; | ||
} | ||
|
||
void operate_ra(t_list **stack_a) | ||
{ | ||
rotate_stack(stack_a); | ||
ft_putendl_fd("ra", STDOUT_FILENO); | ||
} | ||
|
||
void operate_rra(t_list **stack_a) | ||
{ | ||
reverse_rotate_stack(stack_a); | ||
ft_putendl_fd("rra", STDOUT_FILENO); | ||
} |
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 13:28:54 by reasuke #+# #+# */ | ||
/* Updated: 2024/01/15 13:47:24 by reasuke ### ########.fr */ | ||
/* Updated: 2024/01/15 16:56:03 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -23,3 +23,9 @@ void swap_stack(t_list **stack) | |
second->next = *stack; | ||
*stack = second; | ||
} | ||
|
||
void operate_sa(t_list **stack_a) | ||
{ | ||
swap_stack(stack_a); | ||
ft_putendl_fd("sa", STDOUT_FILENO); | ||
} |