forked from davidezra00/Python-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomSort.py
More file actions
63 lines (61 loc) · 829 Bytes
/
RandomSort.py
File metadata and controls
63 lines (61 loc) · 829 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
from random import randint
n=int(input())
i=0
l=[]
c=[]
while i<n:
i+=1
c.append(input())
for i in c:
l.append(int(i))
g=0
v=0
while v<=1000:
m=1
l.append(0)
for i in range(0,n-1):
if l[i]<=l[i+1]:
m+=1
if m==n:
l.pop()
for i in l:
print(i,end=' ')
g=1
else:
pass
l.pop()
if g==1:
break
k=random.randint(0,n-1)
j=random.randint(0,n-1)
if k==j:
continue
a=l[k]
b=l[j]
l.remove(a)
l.remove(b)
l.insert(k,b)
l.insert(j,a)
v+=1
'''
#try this method
from random import randint
a1=int(input())
a=[]
b=[]
for i in range(0,a1) :
a.append(int(input()))
b=a
b.sort()
while True :
if a==b :
print(*a,end='')
break
else :
n1=randint(0,a1+1)
n2=randint(0,a1+1)
m1=a[n1]
m2=a[n2]
a[n1]=m2
a[n2]=m1