-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpartition_sort_a.c
More file actions
59 lines (54 loc) · 1.62 KB
/
partition_sort_a.c
File metadata and controls
59 lines (54 loc) · 1.62 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* partition_sort_a.c :+: :+: */
/* +:+ */
/* By: lorenasmienk <lorenasmienk@student.coda +#+ */
/* +#+ */
/* Created: 2019/12/26 12:43:32 by lorenasmien #+# #+# */
/* Updated: 2020/01/03 12:06:37 by lsmienk ######## odam.nl */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static int count_sorted(t_setting *set, int part)
{
set_min_max(set->a, part);
while (part > 0 && set->a->stack[set->a->len - set->a->len] == set->a->min)
{
part--;
}
return (part);
}
static void push_part(t_setting *set, int part)
{
while (part > 0)
{
push(set->a, set->b, 'b');
part--;
}
}
void partition_sort_a(t_setting *set, int part)
{
int p_part;
int x;
p_part = 0;
x = 0;
while (part > 3)
{
if (is_rev_sorted(set->a, part))
{
push_part(set, part);
part = ret_sorted_bstack(set, part);
break ;
}
part = count_sorted(set, part);
x = push_top(set, part);
part -= x;
p_part += x;
}
small_sort(set, part);
if (p_part > 3)
partition_sort_b(set, p_part);
else
small_b_stack(set, p_part);
}