This paper summarizes the Python selection sorting algorithm. Share to everyone for your reference. Specific as follows:
Code Listing 1:
def ssort (V): #V is the list of sorted j = 0 #j is the ' current ' ordered position, starting with the first one in th E list while j! = Len (V): #this is the replacing so ends when it reaches the end of the list for I in range (J, l En (V)): #here It replaces the minor value that it finds with J position if V[i] < V[j]: #but it does it for Every value minor than position J V[j],v[i] = v[i],v[j] j = j+1 #and Here's the addiction that limits the Ver Ification to the next values
Code Listing 2:
def selection_sort (list): l=list[:] # Create a copy of the list sorted=[] # This new list would hold the results wh Ile Len (L): # While there is elements to sort ... lowest=l[0] # Create a variable to identify lowest for x in L: # and check every item in the list ... if x
Code 3
A=input ("Enter The length of the list:") # too ask the user length of the list l=[]# take a emty list for G in range (a): # For append the values from user b=input ("Enter the Element:") # to ask the user to give list values L.append (b) # To append a values in a empty list L print ' The given eliments list is ', L for I in Range (Len (L)): # To repeat the Loop tak E length of L Index=i # to store the values I in string index Num=l[i] # to take first value in list and store in Nu M for j in Range (I+1,len (L)): # to-Find out-the small value in a list-read all values if NUM>L[J]: # to Compa Re the values which store in num and List Index=j # to store the small value of the Loop J in Index Num=l [j] # to store small charecter is value in num tem=l[i] # to Swaps the list take the Temparary list Stor list Vlau Es L[i]=l[index] # to take first value as another l[index]=tem print "After the swping the list by selection sort is" , l
Hopefully this article will help you with Python programming.