Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def menu():
- print('1. Read file data')
- print('2. Bubble sort')
- print('3. Quick sort / Insertion sort')
- print('4. End')
- def readFile():
- data = []
- file = open('ADMISSIONS-DATA.TXT','r')
- for line in file:
- line = line.strip()
- data.append(line)
- file.close()
- return data
- def BubbleSort(data):
- print(data)
- NoSwaps = False
- while NoSwaps == False:
- NoSwaps = True
- for i in range(49):
- if data[i] > data[i+1]: #swap
- NoSwaps = False
- temp = data[i]
- data[i] = data[i+1]
- data[i+1] = temp
- for i in range(len(data)):
- print(data[i])
- def main():
- menu()
- choice = int(input('Enter choice: '))
- while choice <0 or choice >4: #validation
- print('Invalid input.')
- choice = int(input('Enter choice: '))
- while choice != 4:
- if choice == 1:
- data = readFile()
- elif choice == 2:
- data = readFile()
- BubbleSort(data)
- print(data)
- else:
- InsertionSort(data)
- menu()
- choice = int(input('Enter choice: '))
- while choice <0 or choice >4: #validation
- print('Invalid input.')
- choice = int(input('Enter choice: '))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement