cs325/hw1/inserttime.cpp
//The sorting function that does all the work
The sorting function that does all the work
The sorting function that does all the work
void insertionSort(int *arr, int size) {
	int i, j, val;
	for(i = 1; i < size; i++) {
		val = arr[i];
		j = i - 1;
		while(j >= 0 && arr[j] > val) {
			arr[j + 1] = arr[j];
			j = j - 1;
		}
		arr[j + 1] = val;
	}
}
void insertionSort ( int * arr , int size ) { int i , j , val ; for ( i = 1 ; i < size ; i ++ ) { val = arr [ i ] ; j = i - 1 ; while ( j >= 0 && arr [ j ] > val ) { arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; } arr [ j + 1 ] = val ; } }
The sorting function that does all the work
The sorting function that does all the work
//Initialize variables to be used in function //For loop that runs for the size of the array //The first val looked at is arr[i] //Set j to one less than i every iteration //While j is greater than or equal to 0 and arr[j] > the current value //If this is true, the variables are switched //Decrease j by 1 every time an insertion happens //Set the next value in the array to val