-
Notifications
You must be signed in to change notification settings - Fork 0
/
quartet_quintette.c
90 lines (84 loc) · 2.15 KB
/
quartet_quintette.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* small_sort_part2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eablak <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/20 11:51:06 by eablak #+# #+# */
/* Updated: 2022/12/21 19:06:03 by eablak ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void send_b(t_holder *holder, int i)
{
if (i == 1 && (holder->size_a == 4 || holder->size_a == 5))
ra(&(holder->a));
else if (i == 2 && holder->size_a == 4)
{
rra(&(holder->a));
rra(&(holder->a));
}
else if (i == 2 && holder->size_a == 5)
{
ra(&(holder->a));
ra(&(holder->a));
}
else if ((i == 3 && holder->size_a == 4) || (holder->size_a == 5 && i == 4))
rra(&(holder->a));
else if (i == 3 && holder->size_a == 5)
{
rra(&(holder->a));
rra(&(holder->a));
}
pb(holder);
}
void find_min_data(t_holder *holder)
{
t_struct *begin;
int min;
int i;
begin = holder->a;
min = holder->a->data;
i = 0;
while (holder->a)
{
if (holder->a->data < min)
min = holder->a->data;
holder->a = holder->a->next;
}
holder->a = begin;
while (1)
{
if (begin->data == min)
break ;
begin = begin->next;
i++;
}
send_b(holder, i);
}
void quartet_quintette(t_struct **a, t_struct *b, int size)
{
t_holder *holder;
t_struct *keep_a;
int i;
i = 0;
holder = malloc(sizeof(t_holder));
holder->a = (*a);
keep_a = holder->a;
holder->b = b;
holder->size_a = size;
while (holder->size_a > 3)
{
find_min_data(holder);
i++;
}
triple_sorting(&(holder->a), 0);
while (i > 0)
{
pa(holder);
i--;
}
ft_free(&(holder->a));
free(holder);
}