Advertisement
Guest User

Python Insertion Sort Example

a guest
Jan 29th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. players=[]
  4. scores=[]
  5. def insertion_sort(arr, names):
  6.     for i in range(len(arr)):
  7.         cursor = arr[i]
  8.         ncursor = names[i]
  9.         pos =   i
  10.         while pos > 0 and arr[pos - 1] < cursor:
  11.             arr[pos] = arr[pos - 1]
  12.             names[pos] = names[pos - 1]
  13.             pos = pos - 1
  14.         arr[pos] = cursor
  15.         names[pos] = ncursor
  16.     return  ([arr,names])
  17. for i in range(5):
  18.     p=str(input('ΔΩΣΕ ΟΝΟΜΑ:'))
  19.     players.append(p)
  20.     s=int(input('ΔΩΣΕ SCORE:'))
  21.     scores.append(s)
  22. result=insertion_sort(scores,players)
  23. scores=result[0]
  24. players=result[1]
  25. print (scores)
  26. print (players)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement