Optimized quick_sort to use partition function