From b1b4bdaecddde492a9cca441b9c236ba16ee1d01 Mon Sep 17 00:00:00 2001 From: Chetan Kaushik Date: Tue, 19 Jul 2016 22:34:17 +0530 Subject: [PATCH] Changed extention of previous files and added Selection sort --- BubbleSort.python => BubbleSort.py | 0 InsertionSort.python => InsertionSort.py | 2 -- SelectionSort.py | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) rename BubbleSort.python => BubbleSort.py (100%) rename InsertionSort.python => InsertionSort.py (99%) create mode 100644 SelectionSort.py diff --git a/BubbleSort.python b/BubbleSort.py similarity index 100% rename from BubbleSort.python rename to BubbleSort.py diff --git a/InsertionSort.python b/InsertionSort.py similarity index 99% rename from InsertionSort.python rename to InsertionSort.py index 451f6e905..e0417a755 100644 --- a/InsertionSort.python +++ b/InsertionSort.py @@ -1,5 +1,3 @@ - - array=[]; # input diff --git a/SelectionSort.py b/SelectionSort.py new file mode 100644 index 000000000..89b6977cb --- /dev/null +++ b/SelectionSort.py @@ -0,0 +1,14 @@ +print ("Enter numbers seprated by comma ") +def selectionsort( aList ): + for i in range( len( aList ) ): + least = i + for k in range( i + 1 , len( aList ) ): + if aList[k] < aList[least]: + least = k + + swap( aList, least, i ) + +def swap( A, x, y ): + tmp = A[x] + A[x] = A[y] + A[y] = tmp