All pastes #37022 Raw Edit

lotus_anima

public cpp v1 · immutable
#37022 ·published 2006-01-17 01:25 UTC
rendered paste body
#include <iostream> using namespace std;void fillArray(int a[], unsigned int size, int quit);int smallestInArray(const int* a, unsigned int size, 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] = {0}, quit = -999;	int size = sizeof(a) / sizeof(a[0]);	fillArray(a, size, quit);	// Show the array, unsorted:	cout << "The array, unsorted, is: " << endl;	showArray(a, size, quit);	// Show the array, sorted:	cout << "The array, sorted, is: " << endl;	sortArray(a, size, quit);	showArray(a, size, quit);	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;	for(unsigned int x = 0; a[x-1] != quit && x < size; x++){		cout << "Enter an integer, or " << quit << " to quit: ";		cin >> a[x];	}}int smallestInArray(const int a[], unsigned int size, unsigned int offset){	int indexOfSmallest = offset;	for(unsigned int x = offset+1; x < size; x++){		if(a[x] < a[indexOfSmallest]){			indexOfSmallest = x;		}	}	return indexOfSmallest;}void sortArray(int a[], unsigned int size, int quit){	int y;	for(unsigned int x = 0; x < size-1; x++){		y = smallestInArray(a, size, 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; x++){		cout << x << ": " << a[x] << endl;	}}