Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Code Debugging help( Quick Sort) Why won't it put the lists together? Instead its only returning the pivot + the halfs and they are

Python Code Debugging help( Quick Sort)

Why won't it put the lists together? Instead its only returning the pivot + the halfs and they are only sorted in halves. Please help!

https://gist.github.com/anonymous/d00ce9f39fb06eddd6ecc5bce418e562

def quicksort(Lst, first, last,pivot): if ((last - first) > 0): mid_bin = first pivot2 = pivot for i in range(first, last): if (Lst[i] < Lst[pivot]): Lst[i], Lst[mid_bin] = Lst[mid_bin], Lst[i]; mid_bin += 1

Lst[pivot], Lst[mid_bin] = Lst[mid_bin], Lst[pivot]; quicksort(Lst, first, mid_bin-1,pivot2) quicksort(Lst,mid_bin+1,last,pivot2) return Lst testList1 = [5,2,20,1,55,34,25] testList2 = [1,2,3,4,5,6,7,8,9,10] testList3 = [10,9,8,7,6,5,4,3,2,1]

print(testList1) print(testList2) print(testList3)

pivot = int(input("Enter Pivot Index:")) print hacer1 = quicksort(testList1, 0, len(testList1)-1,pivot) hacer2 = quicksort(testList2, 0, len(testList2)-1,pivot) hacer3 = quicksort(testList3, 0, len(testList3)-1,pivot) print(hacer1) print(hacer2) print(hacer3)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions