-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrategy.c
More file actions
78 lines (73 loc) · 2.14 KB
/
strategy.c
File metadata and controls
78 lines (73 loc) · 2.14 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* strategy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: miissa <miissa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/30 09:34:08 by miissa #+# #+# */
/* Updated: 2026/01/03 14:17:35 by miissa ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
const char *ps_strategy_name(t_strategy s)
{
if (s == START_SIMPLE)
return ("simple");
if (s == START_MEDIUM)
return ("medium");
if (s == START_COMPLEX)
return ("complex");
if (s == START_LOW)
return ("adaptive_low");
return ("adaptive");
}
const char *ps_strategy_complexity(t_strategy s)
{
if (s == START_SIMPLE)
return ("O(n^2)");
if (s == START_MEDIUM)
return ("O(n*sqrt(n))");
if (s == START_COMPLEX)
return ("O(nlog(n))");
if (s == START_LOW)
return ("O(n)");
return ("O(?)");
}
static void run_forced(t_stack *a, t_stack *b, t_ctx *ctx)
{
if (ctx->selected == START_SIMPLE)
{
ctx->used = START_SIMPLE;
sort_simple_using_selection(a, b, ctx);
}
else if (ctx->selected == START_MEDIUM)
{
ctx->used = START_MEDIUM;
sort_medium_using_chunk(a, b, ctx);
}
else if (ctx->selected == START_COMPLEX)
{
ctx->used = START_COMPLEX;
sort_complex(a, b, ctx);
}
else if (ctx->selected == START_ADAPTIVE)
{
ctx->used = sort_adaptive(a, b, ctx);
}
}
void ps_run_strategy(t_stack *a, t_stack *b, t_ctx *ctx)
{
if (!a || !b || !ctx)
return ;
if (a->size <= 3)
{
if (ctx->selected == START_ADAPTIVE)
ctx->used = START_LOW;
else
ctx->used = ctx->selected;
sort_small_stack(a, ctx);
return ;
}
run_forced(a, b, ctx);
}