I am writing a quick sort function and using recursion to "divide and conquer". I am attempting to keep a running count of the number of times the function calls itself. However, I obviously am having trouble with the concept of recursion because I am unable to save a second value to keep a count. I have tried to format the input_string
and loops
as a tuple
or dictionary
but I believe I have a fundamental misunderstanding of how I should do this. How do I pass 2 values to my recursive function successfully?
def quickSort(input_string, loops):
string_list = list(input_string)
less = []
equal = []
greater = []
loops = list(loops)
loops.append(1)
if len(string_list) > 1:
split_val = string_list[0]
for i in string_list:
if i < split_val:
less.append(i)
elif i == split_val:
equal.append(i)
else:
greater.append(i)
out = (quickSort(less, loops) + equal + quickSort(greater, loops)), loops
return out
else:
return string_list
I am using the quick sort function defined here: https://stackoverflow.com/a/18262384/5500488