Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python selectionsort

# Selection sort in Python

def selectionSort(array, size):
   
    for step in range(size):
        min_idx = step

        for i in range(step + 1, size):
         
            # to sort in descending order, change > to < in this line
            # select the minimum element in each loop
            if array[i] < array[min_idx]:
                min_idx = i
         
        # put min at the correct position
        (array[step], array[min_idx]) = (array[min_idx], array[step])


data = [-2, 45, 0, 11, -9]
size = len(data)
selectionSort(data, size)
print('Sorted Array in Ascending Order:')
print(data)
Comment

PREVIOUS NEXT
Code Example
Python :: python how to convert each word of each row to numeric value of a dataframe 
Python :: qmenu 
Python :: print(i) 
Python :: genisim 4.0 words 
Python :: function multiply(a b) 
Python :: how to Capture only the ICMP packet. using bpf 
Python :: python flask many to many relation db 
Python :: decoding to str: need a bytes-like object, list found 
Python :: sqlite basic 
Python :: how to add start menu in python 
Python :: HTML not being displayed properly in Flask, Python 
Python :: How deploy Flask application on Webfaction 
Python :: how to blend pixels in pygame 
Python :: dataframe missing and zero values 
Python :: xchacha20 
Python :: ring Insert Items in list 
Python :: while loop using increment 
Python :: send whats app message using python 
Python :: python get message Exception 
Python :: py3 identify file extension 
Python :: Convert matlab to Python Reddit 
Python :: matplotlib bring plot to front in plots with twin axis 
Python :: dbscan multidimensional data 
Python :: where are dictd dictionaries 
Python :: arrays with name instead of index python 
Python :: python for skip header line 
Python :: https://raw.githubusercontent.com/tim-yao/lighthouse-ci/d32f465bb6cda08ded4ce25c88c43a3103e4940a/.browserslistrc 
Python :: first rows of data frame (specify n by param) 
Python :: Which function is used to read single line from file? 
Python :: sum of the first nth term of series codewars python 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =