fork(1) download
  1. # your code goes here
  2. from random import randint
  3.  
  4. def swap(A,i,j):
  5. temp = A[i]
  6. A[i] = A[j]
  7. A[j] = temp
  8.  
  9. def Partition(A,lb,ub):
  10. Pivot = A[lb]
  11. start = lb
  12. end = ub
  13. while(start < end):
  14. while(A[start] <= Pivot):
  15. start+=1
  16. while(A[end] > Pivot):
  17. end-=1
  18. if(start < end):
  19. swap(A,start,end)
  20. swap(A,lb,end)
  21. return end
  22.  
  23. def QuickSort(A,lb,ub):
  24. if(lb < ub):
  25. loc = Partition(A,lb,ub)
  26. QuickSort(A,lb,loc - 1)
  27. QuickSort(A,loc+1,ub)
  28.  
  29. n=int(input())
  30. m=int(input())
  31.  
  32. A = [];
  33.  
  34. for k in range(n):
  35. A.append(randint(0,m))
  36.  
  37. print(A)
  38.  
  39. QuickSort(A,0,len(A)-1)
  40.  
  41. print(A)
  42.  
  43.  
  44. while A:
  45. A.pop()
Runtime error #stdin #stdout #stderr 0.11s 23380KB
stdin
20
1000
stdout
[50, 480, 628, 225, 312, 474, 830, 412, 888, 406, 1000, 597, 54, 686, 446, 508, 19, 487, 519, 419]
stderr
Traceback (most recent call last):
  File "./prog.py", line 39, in <module>
  File "./prog.py", line 27, in QuickSort
  File "./prog.py", line 27, in QuickSort
  File "./prog.py", line 27, in QuickSort
  File "./prog.py", line 25, in QuickSort
  File "./prog.py", line 14, in Partition
IndexError: list index out of range