-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbig_algorithm.c
More file actions
81 lines (75 loc) · 2.16 KB
/
big_algorithm.c
File metadata and controls
81 lines (75 loc) · 2.16 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* big_algorithm.c :+: :+: */
/* +:+ */
/* By: rcorke <rcorke@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/08/12 14:00:31 by rcorke #+# #+# */
/* Updated: 2019/08/22 16:54:05 by rcorke ######## odam.nl */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void get_next_amount_from_b(t_ps *ps, t_blist *list)
{
int x;
x = 0;
while (x < get_end_list_value(list))
{
push_a(ps);
x++;
}
if (x < 4)
{
sort_3_a(ps);
ps->a_done = 1;
}
else
ps->a_done = 0;
pop_list_end(list);
}
static void a_done_zero(t_ps *ps, t_blist *list)
{
if (ps->a_value < 4)
{
sort_3_a(ps);
ps->a_done = 1;
}
else if (ps->a_value > 3 && ps->a_value < 7)
{
sort_a_by_half(ps, list, ps->a_value);
get_next_amount_from_b(ps, list);
}
else
{
while (ps->a_value > 3 && ps->a_done == 0)
sort_a_by_half(ps, list, ps->a_value);
ps->a_done = 1;
sort_3_a(ps);
}
}
void big_algorithm_three(t_ps *ps)
{
t_blist *list;
list = create_list(ps);
get_x_from_stack_a(ps, ps->size / 2, ps->size, 0);
ps->a_done = 0;
add_to_list_end(list, ps->size / 2);
while (ps->len_a > 3 && ps->a_done == 0)
sort_a_by_half(ps, list, ps->len_a);
while (ps->len_a < ps->size)
{
if (ps->a_done == 0)
a_done_zero(ps, list);
else if (get_end_list_value(list) < 4)
get_next_amount_from_b(ps, list);
else
{
sort_b_by_half(ps, list, get_end_list_value(list), 1);
if (find_unordered_ascending(ps->a, ps->len_a) \
== 0 && get_end_list_value(list) > 6)
sort_b_by_half(ps, list, get_end_list_value(list), 1);
}
}
free(list);
}