-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort.c
54 lines (47 loc) · 1.33 KB
/
sort.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kkalinic <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/07 16:19:55 by kkalinic #+# #+# */
/* Updated: 2021/05/08 15:22:16 by kkalinic ### ########.fr */
/* */
/* ************************************************************************** */
#include "headers/cub_head.h"
void swap(int *xp, int *yp)
{
int temp;
temp = *xp;
*xp = *yp;
*yp = temp;
}
void swap_d(double *xp, double *yp)
{
int temp;
temp = *xp;
*xp = *yp;
*yp = temp;
}
void bubbleSort(double *arr, int *ord, int n)
{
int i;
int j;
i = 0;
j = 0;
while (i < n - 1)
{
while (j < (n - i - 1))
{
if (arr[j] > arr[j + 1])
{
swap_d(&arr[j], &arr[j + 1]);
swap(&ord[j], &ord[j + 1]);
}
++j;
}
j = 0;
++i;
}
}