Skip to content

Instantly share code, notes, and snippets.

@yanddam
Forked from thien/Recursive SelectionSort
Last active January 26, 2018 16:59
Show Gist options
  • Save yanddam/5220ea2c2a5514ff46bd904404f0222d to your computer and use it in GitHub Desktop.
Save yanddam/5220ea2c2a5514ff46bd904404f0222d to your computer and use it in GitHub Desktop.
A recursive SelectionSort algorithm written in python
def selection(list, i, j, flag):
print("i=",i,"j=",j)
size = len(list)
if (i < size - 1):
if (flag):
j = i + 1;
if (j < size):
if (list[i] > list[j]):
list[i], list[j] = list[j], list[i]
selection(list, i, j + 1, 0);
else:
selection(list, i + 1, i+2, 1);
list = [6, 2, 3, 7, 1]
selection(list, 0, 1, 1)
print(list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment