// // sortarray.cpp // CSC 215 // John Rogers // // This program reads up to maxLength integers // into an array, sorts them in increasing order, // prints them out. // #include const int maxLength = 20; int fillArray(int A[]) { int index, enteredValue; cout << "Please enter a value: "; cin >> enteredValue; while (index < maxLength && enteredValue != 0) { A[index] = enteredValue; index++; cout << "Please enter a value: "; cin >> enteredValue; } return index; } void swap(int& i, int& j) { int temp; temp = i; i = j; j = temp; return; } void sortArray(int A[], int length) { int index1, index2, small; for (index1 = 0; index1 < length-1; index1++) { small = index1; for (index2 = index1+1; index2 < length; index2++) { if (A[index2] < A[small]) { small = index2; } } swap(A[small], A[index1]); } return; } void printArray(int A[], int length) { int index; for (index = 0; index < length; index++) { cout << A[index] << endl; } return; } int main() { int A[maxLength]; int length; length = fillArray(A); sortArray(A, length); printArray(A, length); return 0; }