Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. def menu():
  2. print('1. Read file data')
  3. print('2. Bubble sort')
  4. print('3. Quick sort / Insertion sort')
  5. print('4. End')
  6.  
  7.  
  8. def readFile():
  9. data = []
  10. file = open('ADMISSIONS-DATA.TXT','r')
  11.  
  12. for line in file:
  13. line = line.strip()
  14. data.append(line)
  15.  
  16. file.close()
  17.  
  18.  
  19. return data
  20.  
  21. def BubbleSort(data):
  22. print(data)
  23.  
  24. NoSwaps = False
  25.  
  26. while NoSwaps == False:
  27. NoSwaps = True
  28.  
  29. for i in range(49):
  30. if data[i] > data[i+1]: #swap
  31. NoSwaps = False
  32. temp = data[i]
  33. data[i] = data[i+1]
  34. data[i+1] = temp
  35.  
  36. for i in range(len(data)):
  37. print(data[i])
  38.  
  39. def main():
  40.  
  41. menu()
  42.  
  43. choice = int(input('Enter choice: '))
  44.  
  45. while choice <0 or choice >4: #validation
  46. print('Invalid input.')
  47. choice = int(input('Enter choice: '))
  48.  
  49. while choice != 4:
  50. if choice == 1:
  51. data = readFile()
  52.  
  53. elif choice == 2:
  54. data = readFile()
  55. BubbleSort(data)
  56. print(data)
  57. else:
  58. InsertionSort(data)
  59.  
  60. menu()
  61. choice = int(input('Enter choice: '))
  62. while choice <0 or choice >4: #validation
  63. print('Invalid input.')
  64. choice = int(input('Enter choice: '))
  65.  
  66. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement