-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3InOneSorting.py
More file actions
63 lines (54 loc) · 1.72 KB
/
Copy path3InOneSorting.py
File metadata and controls
63 lines (54 loc) · 1.72 KB
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
print("Program that perform three type of sorting they are \n Selection \n Insertion \n Bubble\n")
y=int(input("Enter your choice. \n 1->Selection \n 2->Insertion \n 3-> Bubble \n 4->quit\n"))
while(True):
if(y==1):
n=int(input("Enter the number : "))
print("Enter the element in array")
arr=[]
for i in range(n):
num=int(input())
arr.append(num)
temp=0
for i in range(n):
for j in range(i+1,n):
if(arr[i]>arr[j]):
temp=arr[i]
arr[i]=arr[j]
arr[j]=temp
print("After sorting : ")
print(arr)
elif(y==2):
n=int(input("Enter the size of array : "))
temp=0
arr=[]
print("Enter array element : ")
for i in range(n):
arr.append(int(input()))
for i in range(1,n):
temp=arr[i]
j=i-1
while((temp<arr[j]) and (j>=0)):
arr[j+1]=arr[j]
j-=1
arr[j+1]=temp
print("After Sorting : ")
print(arr)
elif(y==3):
n=int(input("Enter the number : "))
arr=[]
temp=0
print("Enter array element : \n")
for i in range(n):
x=int(input())
arr.append(x)
for i in range(0,n-1):
for j in range(0,n-i-1):
if(arr[j]>arr[j+1]):
temp=arr[j]
arr[j]=arr[j+1]
arr[j+1]=temp
print("After sorting : \n")
print(arr)
else:
quit
print("you are out of the condition: ")