/* ARRAYLIB.C * - array library function definitions */ #include #include #include "arraylib.h" void swapInts(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } /* * copyArray: if a and b are the same length, copies the corresponding * values of a into b */ void copyArray(int a[], int aLen, int b[], int bLen) { int i; if (aLen != bLen) return; /* don't try to copy different sized arrays */ for (i = 0; i < aLen ; i++) b[i] = a[i]; } /* * swapArrays: if a and b are the same length, swaps the corresponding * values of a and b */ void swapArrays(int a[], int aLen, int b[], int bLen) { int i; if (aLen != bLen) return; /* don't try to swap different sized arrays */ for (i = 0; i < aLen ; i++) swapInts(&a[i], &b[i]); } void printArray(int arr[], int arrLen) { int i; for (i = 0; i < arrLen; i++) printf( "%3d ", arr[i]); printf("\n"); }