Solution #1: Here is the code,
void findMinTwo(int* arr, int len) { int i; int min = INT_MAX; int sMin = INT_MAX; for(i=0; i < len; i++) { //if arr[i] is less them min, set min = arr[i] //and set sMin = min if(arr[i] < min) { sMin = min; min = arr[i]; } //else if arr[i] is less then sMin, update sMin else if(arr[i] < sMin) { sMin = arr[i]; } } printf("%d %d\n", min, sMin); }
No comments:
Post a Comment