You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: Selection_Sort.py
+103-2
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,107 @@
9
9
Author: Shriya Madan
10
10
'''
11
11
12
+
#Improvement in input methods
13
+
'''
14
+
To take different type of input " list_input() " main method is called in Driver Code.
15
+
It provides to possible option to user as either user enter the length of array or not.
16
+
if user enter length of array then array takes input for user until length of reached in different interactive form. Some example are given below:-
17
+
example length of array is 10
18
+
input format 1-
19
+
2 3 2 5 5 65 7 4 10 966
20
+
21
+
input format 2-
22
+
52 363
23
+
12 3365
24
+
1252 6662 545322
25
+
12 3
26
+
56
27
+
28
+
input format 3-
29
+
23
30
+
45
31
+
12
32
+
52
33
+
32
34
+
85
35
+
10
36
+
12
37
+
32
38
+
52
39
+
40
+
if user choose option second to not specify the length of array then array store input untill 'user enter '$' or any character except integer or float'
41
+
input format 1-
42
+
2 3 2 5 5 65 7 4 10 966 $
43
+
44
+
input format 2-
45
+
52 363
46
+
12 3365
47
+
1252 6662 545322
48
+
12 3
49
+
56 $
50
+
51
+
input format 3-
52
+
23
53
+
45
54
+
12
55
+
52
56
+
32
57
+
85
58
+
10
59
+
12
60
+
32
61
+
52
62
+
$
63
+
Improved by Kaushal Agarwal
64
+
'''
65
+
66
+
67
+
defwith_length():
68
+
flag=1
69
+
while(flag):
70
+
print("Length of array")
71
+
try:
72
+
n=int(input())
73
+
flag=0
74
+
except:
75
+
flag=1
76
+
77
+
print("It only store first ",n," elements.")
78
+
print("\nEnter your elements.")
79
+
arr=[]
80
+
whilelen(arr)<n:
81
+
val=list(map(float,input().split()))
82
+
length=n-len(arr)
83
+
iflen(val)>length:
84
+
arr=arr+val[:length]
85
+
else:
86
+
arr=arr+val
87
+
returnarr
88
+
defwithout_length():
89
+
print("Array only takes integer or float inputs. Enter '$' to stop")
90
+
arr=list(map(float,input().split()))
91
+
while(1):
92
+
val=input().split()
93
+
forxinval:
94
+
try:
95
+
x=float(x)
96
+
except:
97
+
returnarr
98
+
arr.append(float(x))
99
+
100
+
101
+
deflist_input():
102
+
ch=""
103
+
whilechnotin ['y','n','Y','N']:
104
+
print("Want to specify the length of arry y/n ",end=' ')
105
+
ch=input()
106
+
ifch=='Y'orch=='y':
107
+
arr=with_length()
108
+
returnarr
109
+
else:
110
+
arr=without_length()
111
+
returnarr
112
+
12
113
13
114
defselection_sort(alist):
14
115
"""
@@ -27,11 +128,11 @@ def selection_sort(alist):
27
128
28
129
if__name__=='__main__':
29
130
30
-
arr=[1, 12, 11, -2, 13, 0, 6, 7]
131
+
arr=list_input() # improved way of taking input us list_input()
0 commit comments