summaryrefslogtreecommitdiff
path: root/other/burneye2/testcases/quicksort.c
blob: 2ded6016ffbe3c406ec1affd705ed1abedc1d814 (plain)
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


static int quicksort_verbose = 1;

void
qprint (void)
{
	printf ("calling quicksort\n");
}


void
quicksort (unsigned char *a, int m, int n)
{
	int	i, j, v, x;

	if (n <= m)
		return;

	i = m - 1;
	j = n;
	v = a[n];
	while (1) {
		do
			i = i + 1;
		while (a[i] < v);
		do
			j = j - 1;
		while (a[j] > v);

		if (i >= j)
			break;
		x = a[i];
		a[i] = a[j];
		a[j] = x;
	}
	x = a[i];
	a[i] = a[n];
	a[n] = x;

	qprint ();

	quicksort (a, m, j);
	quicksort (a, i + 1, n);
}

void * quicksort_fptr = (void *) quicksort;