-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_3.c
83 lines (73 loc) · 2.01 KB
/
utils_3.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fsalvett <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 12:04:33 by fsalvett #+# #+# */
/* Updated: 2023/03/31 12:07:05 by fsalvett ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void rotate(t_list **head)
{
t_list *temp;
t_list *new_head;
t_list *temp_end;
temp = *head;
new_head = (*head)->next;
temp_end = *head;
while (temp_end->next != NULL)
{
temp_end = temp_end->next;
}
temp_end->next = temp;
temp->next = NULL;
*head = new_head;
}
void reverse_rotate(t_list **head)
{
t_list *temp_penultimate;
t_list *temp_end;
temp_end = *head;
temp_penultimate = *head;
while (temp_end->next != NULL)
{
temp_end = temp_end->next;
}
while (temp_penultimate->next && temp_penultimate->next->next != NULL)
{
temp_penultimate = temp_penultimate->next;
}
temp_end->next = *head;
temp_penultimate->next = NULL;
*head = temp_end;
}
void ra(t_list **head)
{
rotate(head);
write(1, "ra\n", 3);
}
void sa(t_list **head)
{
int temp;
if ((*head)->next != NULL)
{
temp = (*head)->value;
(*head)->value = (*head)->next->value;
(*head)->next->value = temp;
write(1, "sa\n", 3);
}
}
void sb(t_list **head_2)
{
int temp;
if ((*head_2)->next != NULL)
{
temp = (*head_2)->value;
(*head_2)->value = (*head_2)->next->value;
(*head_2)->next->value = temp;
write(1, "sb\n", 3);
}
}