-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_sort_array.c
More file actions
56 lines (49 loc) · 1.41 KB
/
quick_sort_array.c
File metadata and controls
56 lines (49 loc) · 1.41 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* quick_sort_array.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yaqliu <yaqliu@student.42barcelona.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/07 14:16:36 by yaqliu #+# #+# */
/* Updated: 2026/02/12 00:15:20 by yaqliu ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
void ft_swap(int *a, int *b)
{
int aux;
aux = *a;
*a = *b;
*b = aux;
}
int partition(int *arr, int ini, int fi)
{
int pivot;
int i;
int j;
pivot = arr[fi];
i = (ini - 1);
j = ini;
while (j < fi)
{
if (arr[j] < pivot)
{
i++;
ft_swap(&arr[i], &arr[j]);
}
j++;
}
ft_swap(&arr[i + 1], &arr[fi]);
return (i + 1);
}
void quick_sort_array(int *arr, int ini, int fi)
{
int n;
if (ini < fi)
{
n = partition(arr, ini, fi);
quick_sort_array(arr, ini, n - 1);
quick_sort_array(arr, n + 1, fi);
}
}