Get Quicksort list as a whole to visualize while using recursion

33 views Asked by At

So I wrote this method for Quicksort. I know it isn't the most efficient, but it is what I came along with. The plan is to have a list that shows the list as a whole so that I can visualize it in my GUI.

def quickSort(self, element_list=None):
        
        if element_list == None:
            element_list = self.data

        if len(element_list) < 2:
            return element_list  # Return a list with a single element

        pivot = element_list[-1]
        del element_list[-1]

        # List for values lower and higher than pivot
        splited_list = [[], []]

        for value in element_list:
            if value <= pivot:
                splited_list[0].append(value)
            else:
                splited_list[1].append(value)
        
        return self.quickSort(splited_list[0]) + [pivot] + self.quickSort(splited_list[1])

When using this list [27, 13, 6, 42, 19, 8, 35, 11] the list should look something like this over time:

[6, 8, 11, 27, 13, 42, 19, 35]
[6, 8, 11, 27, 13, 42, 19, 35]
[6, 8, 11, 27, 13, 19, 35, 42]
[6, 8, 11, 13, 19, 27, 25, 42]

I looked for different methods, but none of them worked and I'm out of ideas, so maybe one of you guys could help :)

0

There are 0 answers