diff options
| author | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
| commit | 4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch) | |
| tree | 868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /examples/bubsort.c | |
| parent | eae0bd57f0a26314a94785061888d193d186944a (diff) | |
| download | progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2 progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip | |
reorganize file structure to match the upstream requirements
Diffstat (limited to 'examples/bubsort.c')
| -rw-r--r-- | examples/bubsort.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/bubsort.c b/examples/bubsort.c new file mode 100644 index 0000000..343219e --- /dev/null +++ b/examples/bubsort.c | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | /* sort.c | ||
| 2 | |||
| 3 | Test program to sort a large number of integers. | ||
| 4 | |||
| 5 | Intention is to stress virtual memory system. | ||
| 6 | |||
| 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> | ||
| 10 | |||
| 11 | /* Size of array to sort. */ | ||
| 12 | #define SORT_SIZE 128 | ||
| 13 | |||
| 14 | int | ||
| 15 | main (void) | ||
| 16 | { | ||
| 17 | /* Array to sort. Static to reduce stack usage. */ | ||
| 18 | static int array[SORT_SIZE]; | ||
| 19 | |||
| 20 | int i, j, tmp; | ||
| 21 | |||
| 22 | /* First initialize the array in descending order. */ | ||
| 23 | for (i = 0; i < SORT_SIZE; i++) | ||
| 24 | array[i] = SORT_SIZE - i - 1; | ||
| 25 | |||
| 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]) | ||
| 30 | { | ||
| 31 | tmp = array[j]; | ||
| 32 | array[j] = array[j + 1]; | ||
| 33 | array[j + 1] = tmp; | ||
| 34 | } | ||
| 35 | |||
| 36 | printf ("sort exiting with code %d\n", array[0]); | ||
| 37 | return array[0]; | ||
| 38 | } | ||
