forked from sinha414tanya/tsinha
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_it_up
More file actions
36 lines (32 loc) · 799 Bytes
/
sort_it_up
File metadata and controls
36 lines (32 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#Sort it up
# arr=[2,0,1,0,2]
arr=list(map(int, input().split()))
n=len(arr)
def inplaceSorting_O_n2(arr):
for i in range(0,n):
for j in range(i+1, n):
if arr[i]>arr[j]:
temp=arr[j]
arr[j]=arr[i]
arr[i]=temp
return arr
def inplaceSorting_O_n(arr):
n=len(arr)
start=0
end=n-1
current=0
while current<=end:
if arr[current]==2:
arr[current]=arr[end]
arr[end]=2
end=end-1
elif arr[current]==0:
arr[current]=arr[start]
arr[start]=0
start=start+1
current=current+1
else:
current=current+1
return arr
print(inplaceSorting_O_n2(arr))
print(inplaceSorting_O_n(arr))