changed to only single for loop in quick for to reduce time complexity. thanks to mr. lalit hinduja
This commit is contained in:
parent
d8ad39d234
commit
3a6ad7c77f
@ -12,16 +12,14 @@ def quickSort(arr):
|
|||||||
'''
|
'''
|
||||||
## ALTERNATIVE WAY OF WRITING THE UPPER 3 LINES (for easy understanding)
|
## ALTERNATIVE WAY OF WRITING THE UPPER 3 LINES (for easy understanding)
|
||||||
left = [] # Empty list to store left part
|
left = [] # Empty list to store left part
|
||||||
|
middle = [] # Empty list to store middle element
|
||||||
|
right = [] # Empty list to store right part
|
||||||
for i in arr:
|
for i in arr:
|
||||||
if (i < pivot):
|
if (i < pivot):
|
||||||
left.append(i)
|
left.append(i)
|
||||||
middle = [] # Empty list to store middle element
|
elif (i == pivot):
|
||||||
for i in arr:
|
|
||||||
if (i == pivot):
|
|
||||||
middle.append(i)
|
middle.append(i)
|
||||||
right = [] # Empty list to store right part
|
else:
|
||||||
for i in arr:
|
|
||||||
if (i > pivot):
|
|
||||||
right.append(i)
|
right.append(i)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@ -47,4 +45,4 @@ def main():
|
|||||||
|
|
||||||
# Calling main function:
|
# Calling main function:
|
||||||
main()
|
main()
|
||||||
# END OF CODE
|
# END OF CODE
|
||||||
|
Loading…
Reference in New Issue
Block a user