Changed BubbleSort.py and InsertionSort.py to allow x number of inputs. Also worked on LinearSearch.py
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
def simple_insertion_sort(int_list):
|
||||
for i in range(1, 6):
|
||||
count = len(int_list)
|
||||
for i in range(1, count):
|
||||
temp = int_list[i]
|
||||
j = i - 1
|
||||
while(j >= 0 and temp < int_list[j]):
|
||||
@@ -11,13 +12,15 @@ def simple_insertion_sort(int_list):
|
||||
return int_list
|
||||
|
||||
|
||||
def main(num):
|
||||
inputs = []
|
||||
print('Enter any {} numbers for unsorted list: '.format(num))
|
||||
def main():
|
||||
try:
|
||||
for i in range(num):
|
||||
n = input()
|
||||
inputs.append(n)
|
||||
print("Enter numbers separated by spaces:")
|
||||
s = raw_input()
|
||||
inputs = list(map(int, s.split(' ')))
|
||||
if len(inputs) < 2:
|
||||
print('No Enough values to sort!')
|
||||
raise Exception
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
@@ -26,5 +29,4 @@ def main(num):
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('==== Insertion Sort ====\n')
|
||||
list_count = 6
|
||||
main(list_count)
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user