4 void swap(int* v1
, int* v2
) {
10 /** Display the array on standard output. */
11 void displayArray(int* array
, int count
) {
12 for (int tabIndex
= 0; tabIndex
< count
; ++tabIndex
) {
13 printf("array[%d] = %d\n", tabIndex
, array
[tabIndex
]);
17 /** Perform one swap on the first two values not in increasing order.
19 * @return true if a swap was performed, false if the whole array is ordered.
21 bool sortFirst(int* array
, int length
) {
22 for (int tabIndex
= 0; tabIndex
< (length
- 1); ++tabIndex
) {
23 if (array
[tabIndex
] > array
[tabIndex
+ 1]) {
24 swap(&array
[tabIndex
], &array
[tabIndex
+ 1]);
32 void sortArray(int* array
, int length
) {
36 swappedValues
= sortFirst(array
, length
);
37 } while (swappedValues
);
41 int arr
[10] = {23, 2, 0, 4, 56, 3, 7, 8, 98, 1};
43 displayArray(arr
, 10);