#include using namespace std; void fillArray(int a[], unsigned int size, int quit); int smallestInArray(const int* a, unsigned int size, int quit, unsigned int offset=0); void sortArray(int a[], unsigned int size, int quit); void swapValues(int& x, int& y); void showArray(int a[], unsigned int size, int quit, unsigned int offset = 0); int main(){ int a[10], quit = -999, size = sizeof(a) / sizeof(a[0]), y = 1; fillArray(a, size, quit); sortArray(a, size, quit); cout << "\nN\t\tCount" << endl; for(unsigned int x = 0; x < size && a[x] != quit; x++){ cout << a[x] << "\t\t"; while(a[x] == a[x+1]){ x++; y++; } cout << y << endl; y = 1; } return 0; } void fillArray(int a[], unsigned int size, int quit){ cout << "You can enter a maximum of " << size << " elements." << endl; cout << "Enter " << quit << " to quit." << endl; unsigned int x = 0; do{ cout << "Enter an integer, or " << quit << " to quit: "; cin >> a[x]; x++; } while(x < size && a[x-1] != -999); } int smallestInArray(const int a[], unsigned int size, int quit, unsigned int offset){ int indexOfSmallest = offset; for(unsigned int x = offset+1; x < size && a[x] != quit; x++){ if(a[x] < a[indexOfSmallest]){ indexOfSmallest = x; } } return indexOfSmallest; } void sortArray(int a[], unsigned int size, int quit){ int y; if(a[1] != -999){ for(unsigned int x = 0; x < size-1 && a[x] != quit; x++){ y = smallestInArray(a, size, quit, x); swapValues(a[x], a[y]); } } } void swapValues(int& x, int& y){ int tmp; tmp = x; x = y; y = tmp; } void showArray(int a[], unsigned int size, int quit, unsigned int offset){ for(unsigned int x = offset; x < size && a[x] != quit; x++){ cout << x << ": " << a[x] << endl; } }