Repository navigation
Expand file tree
/
Copy pathinstruction.c
More file actions
97 lines (88 loc) · 2.15 KB
/
Copy pathinstruction.c
File metadata and controls
97 lines (88 loc) · 2.15 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* instruction.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aasselma <aasselma@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/14 01:26:27 by aasselma #+# #+# */
/* Updated: 2023/04/17 21:46:01 by aasselma ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_swap(t_stack *stored, char *str)
{
int num;
int i;
i = -1;
num = stored->stored[0];
stored->stored[0] = stored->stored[1];
stored->stored[1] = num;
if (str != NULL)
{
while (i++ != ft_strlen(str) - 1)
write(1, &str[i], 1);
write(1, "\n", 1);
}
}
void swap_a_b(t_stack *stored_a, t_stack *stored_b, char *str)
{
int i;
i = -1;
ft_swap(stored_a, NULL);
ft_swap(stored_b, NULL);
if (str != NULL)
{
while (i++ != ft_strlen(str) - 1)
write(1, &str[i], 1);
write(1, "\n", 1);
}
}
void ft_rotate(t_stack *stored, char *str)
{
int first;
int i;
i = 0;
first = stored->stored[0];
while (i != stored->len)
{
stored->stored[i] = stored->stored[i + 1];
if ((i + 2) == stored->len)
{
stored->stored[i + 1] = first;
break ;
}
i++;
}
i = -1;
if (str != NULL)
{
while (i++ != ft_strlen(str) - 1)
write(1, &str[i], 1);
write(1, "\n", 1);
}
}
void ft_rev_res(t_stack *stored, char *str)
{
int last;
int i;
i = stored->len - 1;
last = stored->stored[i];
while (i != 0)
{
stored->stored[i] = stored->stored[i - 1];
if ((i - 1) == 0)
{
stored->stored[i - 1] = last;
break ;
}
i--;
}
i = -1;
if (str != NULL)
{
while (i++ != ft_strlen(str) - 1)
write(1, &str[i], 1);
write(1, "\n", 1);
}
}