-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_small.c
39 lines (36 loc) · 1.42 KB
/
ft_small.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_small.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mleitner <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/06 18:04:59 by mleitner #+# #+# */
/* Updated: 2023/02/27 16:16:29 by mleitner ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_push_swap.h"
//performs optimal sort on three values
void small_sort(int *val)
{
int max;
int min;
max = find_max(val, 3);
min = find_min(val, 3);
if (val[1] == min && val[2] == max)
swap(&val[0], &val[1], 1);
else if (val[1] == max && val[2] == min)
r_rotate(val, 3, 1);
else if (val[0] == max && val[1] == min)
rotate(val, 3, 1);
else if (val[0] == max && val[2] == min)
{
swap(&val[0], &val[1], 1);
r_rotate(val, 3, 1);
}
else if (val[0] == min && val[1] == max)
{
swap(&val[0], &val[1], 1);
rotate(val, 3, 1);
}
}