def QS(l): pivot = len(l) - 1 lo = 0 if (lo == pivot or pivot < 0): return l else: lo = QuickSort.findGreaterValue(lo, pivot, l) while (pivot != lo): Sort.switchIndices(pivot - 1, lo, l) lo = QuickSort.findGreaterValue(lo, pivot, l) Sort.switchIndices(pivot, pivot - 1, l) pivot -= 1 temp = [] temp.append(l[pivot]) pList = QuickSort.partitionList(l, pivot) return (QuickSort.QS(pList[0]) + temp + QuickSort.QS(pList[1]))
def IS(l): frameList = [] frameList.append(l[:]) x = 1 #While there exists unordered list elements while (x < len(l)): tempx = x a = x - 1 #Move elements left-to-right to find sorted place for current index while (l[tempx] < l[a] and a >= 0): Sort.switchIndices(tempx, a, l) tempx = a a -= 1 frameList.append(l[:]) x += 1 #next index return frameList