-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.c
113 lines (104 loc) · 2.68 KB
/
functions.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eablak <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 18:05:21 by eablak #+# #+# */
/* Updated: 2022/12/20 16:18:30 by eablak ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void rra_utils(t_struct_rra *s_rra, t_struct **a)
{
s_rra->x->next = s_rra->dont_lose_begin;
s_rra->last_free = s_rra->x;
while (s_rra->j < s_rra->i)
{
s_rra->last_free = s_rra->last_free->next;
s_rra->j++;
}
s_rra->last_free->next = NULL;
(*a) = s_rra->x;
write(1, "rra\n", 4);
free(s_rra);
}
void rra(t_struct **a)
{
t_struct_rra *s_rra;
s_rra = malloc(sizeof(t_struct_rra));
s_rra->x = malloc(sizeof(t_struct));
s_rra->i = 0;
s_rra->j = 0;
s_rra->begin = (*a);
s_rra->dont_lose_begin = s_rra->begin;
while (s_rra->begin->next)
{
s_rra->begin = s_rra->begin->next;
s_rra->i++;
}
s_rra->x->data = s_rra->begin->data;
s_rra->x->next = NULL;
free(s_rra->begin);
rra_utils(s_rra, a);
}
void rrb_utils(t_struct_rra *s_rrb, t_struct **b)
{
s_rrb->x->next = s_rrb->dont_lose_begin;
s_rrb->last_free = s_rrb->x;
while (s_rrb->j < s_rrb->i)
{
s_rrb->last_free = s_rrb->last_free->next;
s_rrb->j++;
}
s_rrb->last_free->next = NULL;
(*b) = s_rrb->x;
write(1, "rrb\n", 4);
free(s_rrb);
}
void rrb(t_struct **b)
{
t_struct_rra *s_rrb;
s_rrb = malloc(sizeof(t_struct_rra));
if ((*b)->next == NULL)
return ;
s_rrb->x = malloc(sizeof(t_struct));
s_rrb->i = 0;
s_rrb->j = 0;
s_rrb->begin = (*b);
s_rrb->dont_lose_begin = s_rrb->begin;
while (s_rrb->begin->next)
{
s_rrb->begin = s_rrb->begin->next;
s_rrb->i++;
}
s_rrb->x->data = s_rrb->begin->data;
s_rrb->x->next = NULL;
free(s_rrb->begin);
rrb_utils(s_rrb, b);
}
int *bubble_sort(int *numeros, int size)
{
int i;
int tmp;
while (size >= 0)
{
i = 0;
while (i < size - 1)
{
if (numeros[i] > numeros[i + 1])
{
tmp = numeros[i];
numeros[i] = numeros[i + 1];
numeros[i + 1] = tmp;
}
i++;
}
size--;
}
return (numeros);
}