//Xinnuo Wanng                CS1A                        Chapter 8 #9 Page.488
/*******************************************************************************
 * Sort Arrays
 * _____________________________________________________________________________
 * The program uses two arrays of at least 20 integers.One calling uses bubble 
 * sort and the other uses selection sort. Both of them need to count the number 
 * of exchanges.
 * _____________________________________________________________________________
 * Input
 *    num1    : The number of exchange in bubble sort.
 *    num2    : The number of exchange in selection sort.
 * 
 * ****************************************************************************/
 
#include <iostream>
using namespace std;
void bubble(int arr[], int size);
void selection (int arr2[], int size2);
void swap (int & a, int &b);
void print(int arr[],int size);

int main() 
{
    int arr[]={26791, 33445, 79422, 13579,93121,62483, 55555, 
 77777, 85647,  26793};
    int size = sizeof(arr)/sizeof (arr[0]);
    bubble (arr,size);
    print (arr,size);
    cout<<endl;
    int arr2[]={
    	2341, 4523, 22, 3412, 2711, 8999, 9999,8876, 6767, 2323, 9922,1111
    };
    int size2 = sizeof(arr2)/sizeof (arr2[0]);
    selection(arr2, size2);
    print(arr2,size2);
    
    
	return 0;
}
void bubble(int arr[], int size)
{
	for (int i = size-1; i > 0; i--)
	{
		for (int j= 0; j < i; j++)
		{
			if (arr[j]>arr[j+1])
			{
				swap (arr[j],arr[j+1]);
			}
		}
	}
}
void selection (int arr2[], int size2)
{
	for(int start = 0; start < size2; start ++)
	{
		int minIndex = start;
		for (int i =start+1; i <size2; i++)
		{
			if (arr2[minIndex]> arr2[i])
			{
			minIndex =i;	
			}
		}
		swap(arr2[minIndex], arr2[start]);
	}
}
void print(int arr[],int size)
{
	for(int i =0; i< size; i++)
	{
		cout << arr[i]<<" ";
	}
}
void swap (int &a, int & b)
{
	int temp = a;
	a=b;
	b=temp;
}