// Find the minimum of an array using pointers int min(int *array, int SIZE) { int min = *array; for(int *p = array+1; p < array+SIZE; p++) if (*p < min) min = *p; return min; }
// Sort an array using pointers void sort(int *array, int SIZE) { for(int *left = array; left < array+SIZE; left++) for(int *right = left+1; right <= array+SIZE; right++) if (*right < *left) swap(left, right); } // Find an element in an array // Return true/false if element is present or not int contains(int *array, int SIZE, int target) int *low = array; int *mid = array+SIZE/2; int *high = array+SIZE-1; while (low < high) { if (*mid < target) low = mid; else if (*mid == target) return 1; else high = mid; } return 0; } // Sort an array of STRINGS. // Remember that each string is itself an array of char int sort_strings(char *(array[]), int SIZE) { for(char *left = &array[0]; left < &array[SIZE]; left++) for(int *right = left+1; right <= array[SIZE]; right++) if (strcmp(left, right) > 0) string_swap(left, right); } void string_swap(char *left, char *right) { char tmp[MAX_SIZE]; strcpy(tmp,left); strcpy(left, right); strcpy(right, tmp); }