Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def print_function(arr,low,high):
- for i in range(low,high+1):
- print(arr[i],end=" ")
- print()
- def partition(arr,low,high):
- pivot=high
- i=high-1
- j=low
- while(i>=j):
- while(arr[j]<arr[pivot]):
- j=j+1
- while(arr[i]>arr[pivot]):
- i=i-1
- if(i>j):
- temp=arr[i]
- arr[i]=arr[j]
- arr[j]=temp
- temp=arr[j]
- arr[j]=arr[pivot]
- arr[pivot]=temp
- p=j
- return p
- def InsertionSort(arr,low,high):
- for i in range(low+1,high+1):
- var=i
- for j in range(i-1,-1,-1):
- if(arr[var]<arr[j]):
- temp=arr[j]
- arr[j]=arr[var]
- arr[var]=temp
- var=j
- return
- def QuickSort(arr,low,high):
- global T
- if (high>low):
- p=partition(arr,low,high)
- l1=p-low
- l2=high-p
- if (l1<T):
- InsertionSort(arr,low,p-1)
- else:
- QuickSort(arr,low,p-1)
- if(l2<T):
- InsertionSort(arr,p+1,high)
- else:
- QuickSort(arr,p+1,high)
- return
- A=list(map(int,input().split()))
- N=A[0]
- global T
- T=A[1]
- arr=[A[i+2] for i in range(0,N)]
- low=0
- high=len(arr)-1
- if(high-low+1<T):
- InsertionSort(arr,low,high)
- else:
- QuickSort(arr,low,high)
- print_function(arr,low,high)
- # 7 5 10 80 30 90 40 50 70
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement