Quicksort 1 - Partition

Sort by

recency

|

389 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/2HD41pYh8cU

    vector<int> quickSort(vector<int> arr) {
        vector<int> left, equal, right;
        for(int i = 0; i < arr.size(); i++){
            if(arr[i] < arr[0]) left.push_back(arr[i]);
            else if(arr[i] > arr[0]) right.push_back(arr[i]);
            else equal.push_back(arr[i]);
        }
        left.insert(left.end(), equal.begin(), equal.end());
        left.insert(left.end(), right.begin(), right.end());
        return left;
    }
    
  • + 0 comments

    python3:

        left = []
    right = []
    equal = [arr[0]]
    for i in range(1,len(arr)):
        if arr[i] > arr[0]:
            right.append(arr[i])
        else:
            left.append(arr[i])
    x = left + equal + right
    return x
    
  • + 0 comments

    The quicksort algorithm in Ruby

    def quickSort(arr)
        # Write your code here
        return arr if arr.length <= 1
    
        pivot = arr.delete_at(arr.length / 2)  # Select the pivot element
        left, right = arr.partition { |x| x < pivot }  # Partition the array
    
        # Recursively sort and combine
        return quickSort(left) + [pivot] + quickSort(right)
    
    end
    
  • + 0 comments

    Thanks for the solution and also for the video for explanation. I was pressed for time with a difficult assignment so I turned to https://domypaper.com/ The service was exceptional The writer followed all my instructions perfectly and delivered a well-researched and polished paper The entire process was smooth and the paper arrived before the deadline I’m beyond satisfied with the results and would highly recommend this service to anyone in need of academic assistance

  • + 0 comments
    def quickSort(arr):
        p = arr[0]
        left, equal, right = list(), [p], list()
        for a in arr[1:]:
            if a < p:
                left.append(a)
            if a > p:
                right.append(a)
        return left + equal + right