Home  >  Article  >  Backend Development  >  Python implements selection sorting

Python implements selection sorting

巴扎黑
巴扎黑Original
2016-12-07 10:53:051338browse

#!/usr/bin/env python

#coding=utf-8

#ChooseSort.py

#user can choose sort style: desc(1) or asc(2)

import stdinInput

def chooseSort( sortArray):

    arrayl=len(sortArray)

    if(arrayl<1):

        return

    

    for i in xrange(0,arrayl-1):

        min=i;

        for j in xrange(i+1,arrayl):

            if(sortArray[j]

                min=j

        sortArray[i],sortArray[min]=sortArray[min],sortArray[i]


if __name__=='__main__':

    stdinInput.stdinInput()

    chooseSort(stdinInput.intsortArrays)

    print stdinInput.intsortArrays


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:python range() methodNext article:python range() method