-
Notifications
You must be signed in to change notification settings - Fork 0
/
first_instructions_bonus.c
63 lines (55 loc) · 1.87 KB
/
first_instructions_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* first_instructions_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abazerou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/26 12:20:51 by abazerou #+# #+# */
/* Updated: 2023/06/10 11:53:23 by abazerou ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void push_a(t_list **head_b, t_list **stack_a, char *s)
{
t_list *tmp_b;
if (!*head_b)
return ;
tmp_b = *head_b;
(*head_b) = (*head_b)->next;
ft_lstadd_front(stack_a, ft_lstnew(tmp_b->data, tmp_b->index));
free(tmp_b);
ft_putstr_fd_bonus(s, 1);
}
void push_b(t_list **head_a, t_list **stack_b, char *s)
{
t_list *tmp_a;
if (!*head_a)
return ;
tmp_a = *head_a;
(*head_a) = (*head_a)->next;
ft_lstadd_front(stack_b, ft_lstnew(tmp_a->data, tmp_a->index));
ft_putstr_fd_bonus(s, 1);
free(tmp_a);
}
void swap(t_list **head, char *s)
{
t_list *tmp_head;
int tmp;
int in;
if ((*head) == NULL || ((*head)->next == NULL))
return ;
tmp_head = (*head);
tmp = (*head)->data;
in = tmp_head->index;
tmp_head->data = tmp_head->next->data;
tmp_head->index = tmp_head->next->index;
tmp_head->next->index = in;
tmp_head->next->data = tmp;
ft_putstr_fd_bonus(s, 1);
}
void rrr(t_list **stack_a, t_list **stack_b)
{
reverse_rotate_a(stack_a, 0);
reverse_rotate_b(stack_b, 0);
}