Wording improvements, from "Valentin I. Spitkovsky"
[pintos.git] / src / examples / bubsort.c
blob343219ec26d39d54514aa91b876a87e765c28b3b
1 /* sort.c
3 Test program to sort a large number of integers.
5 Intention is to stress virtual memory system.
7 Ideally, we could read the unsorted array off of the file
8 system, and store the result back to the file system! */
9 #include <stdio.h>
11 /* Size of array to sort. */
12 #define SORT_SIZE 128
14 int
15 main (void)
17 /* Array to sort. Static to reduce stack usage. */
18 static int array[SORT_SIZE];
20 int i, j, tmp;
22 /* First initialize the array in descending order. */
23 for (i = 0; i < SORT_SIZE; i++)
24 array[i] = SORT_SIZE - i - 1;
26 /* Then sort in ascending order. */
27 for (i = 0; i < SORT_SIZE - 1; i++)
28 for (j = 0; j < SORT_SIZE - 1 - i; j++)
29 if (array[j] > array[j + 1])
31 tmp = array[j];
32 array[j] = array[j + 1];
33 array[j + 1] = tmp;
36 printf ("sort exiting with code %d\n", array[0]);
37 return array[0];