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 /** Swap every out-of-order cells at most once.
19 * @return true if a swap was performed, false if the whole array is ordered.
21 bool sortFirst(int* array
, int length
) {
22 bool swappedValues
= false;
24 for (int tabIndex
= 0; tabIndex
< (length
- 1); ++tabIndex
) {
25 if (array
[tabIndex
] > array
[tabIndex
+ 1]) {
26 swap(&array
[tabIndex
], &array
[tabIndex
+ 1]);
34 void sortArray(int* array
, int length
) {
38 swappedValues
= sortFirst(array
, length
);
39 } while (swappedValues
);
42 /** Fill the array with user input. */
43 void promptArray(int* array
, int length
) {
44 for (int tabIndex
= 0; tabIndex
< length
; ++tabIndex
) {
45 printf("Enter value for index %d:\n", tabIndex
);
46 scanf("%d", &array
[tabIndex
]);
54 displayArray(arr
, 10);