..

Bubble Sort

Here’s a quick and dirty C code that I wrote for Mini-Max Sum in HackerRank.

#define ARR_COUNT_MAX 5
void miniMaxSum(int arr_count, int* arr) {
    long int sorted_array[ARR_COUNT_MAX]={0};
    bool needMore=false;
    for(int i=0;i<arr_count;i++){
        for(int j=0;j<arr_count-(i+1);j++){
            if(arr[j]>arr[j+1]){
                int temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
                needMore=true;
            }
        }
        if(!needMore){
            break;
        }
        needMore=false;
    }
    // the question always had 5-element arrays.
    printf("%ld %ld",(long)arr[0]+arr[1]+arr[2]+arr[3],(long)arr[4]+arr[3]+arr[2]+arr[1]);
}