Quicksort 1 - Partition

  • + 0 comments

    My C code solution

    int* quickSort(int arr_count, int* arr, int* result_count) {
        *result_count = arr_count;
        int j = 0,pivot = arr[0];
        int* ar = (int*)malloc(arr_count*sizeof(int));
        
        for(int i = 0;i < arr_count;i++){
            if(arr[i] < pivot){
                ar[j++] = arr[i];
            }
        }
        
        ar[j++] = pivot;
        for(int i = 0;i < arr_count;i++){
            if(arr[i] > pivot){
                ar[j++] = arr[i];
            }
        }
        return ar;
    }