All pastes #37049 Raw Edit

lotus_anima

public cpp v1 · immutable
#37049 ·published 2006-01-17 07:20 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, int quit, unsigned int offset=0);void sortArray(int a[], unsigned int size, int quit, bool order = 0);void swapValues(int& x, int& y);void showArray(int a[], unsigned int size, int quit, unsigned int offset = 0);void reverseArray(int a[], unsigned int size, int quit);int main(){	int a[17], quit = -999, size = sizeof(a) / sizeof(a[0]), y = 1;	if(size > 50){		cerr << "The array may not have more than 50 elements." << endl;		exit(1);	}	fillArray(a, size, quit);	sortArray(a, size, quit, 1);	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){	unsigned int x = 0;	cout << "You can enter a maximum of " << size << " elements." << endl;	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, bool order){	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]);		}	}	if(order == 1){		reverseArray(a, size, quit);	}}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 << "booyahhh" << endl;		cout << x << ": " << a[x] << endl;	}}void reverseArray(int a[], unsigned int size, int quit){	unsigned int quitIndex = 51;	for(unsigned int x = 0; x < size && quitIndex == 51; x++){		if(a[x] == quit){			quitIndex = x;		}	}	if(quitIndex != 51){		size = quitIndex;	}        for(unsigned int x = 0; x < (size/2); x++){                swapValues(a[x], a[(size-1)-x]);        }}