sort.c
// merges array2 into array1
// n1 n2: lengths or array1 array2
merges array2 into array1
n1 n2: lengths or array1 array2
merges array2 into array1 n1 n2 : lengths or array1 array2
void merge(int array1[], int array2[], int n1, int n2, int auxiliary[]) {
	int i, j, k;
	for (i = 0; i < n1; ++i) {
		auxiliary[i] = array1[i];
	}
	i = 0;	
	j = 0;	
	k = 0;	
	while (i < n1 && j < n2) {
		if (auxiliary[i] < array2[j]) {
			array1[k] = auxiliary[i];
			++i;
		} else {
			array1[k] = array2[j];
			++j;
		}
		++k;
	}
	while (i < n1) {
		array1[k] = auxiliary[i];
		++k;
		++i;
	}
	while (i < n1) {
		array1[k] = array2[j];
		++k;
		++j;
	}
}
void merge ( int array1 [ ] , int array2 [ ] , int n1 , int n2 , int auxiliary [ ] ) { int i , j , k ; for ( i = 0 ; i < n1 ; ++ i ) { auxiliary [ i ] = array1 [ i ] ; } i = 0 ; j = 0 ; k = 0 ; while ( i < n1 && j < n2 ) { if ( auxiliary [ i ] < array2 [ j ] ) { array1 [ k ] = auxiliary [ i ] ; ++ i ; } else { array1 [ k ] = array2 [ j ] ; ++ j ; } ++ k ; } while ( i < n1 ) { array1 [ k ] = auxiliary [ i ] ; ++ k ; ++ i ; } while ( i < n1 ) { array1 [ k ] = array2 [ j ] ; ++ k ; ++ j ; } }
merges array2 into array1
n1 n2: lengths or array1 array2
merges array2 into array1 n1 n2 : lengths or array1 array2
// copy array1 to auxiliary // index of auxiliary // index of array2 // index of array1 // keep coping the smallest element to array1 // until one of the array is empty // copy the remaining elements of auxiliary to array1 // copy the remaining elements of array2 to array1