Browse Source
			
			
			Merge pull request #15 from somiljain7/master
			
				Added selection sort.
			
			
				pull/18/head
			
			
		 
		
			
				
					
						 Jeffery Russell
					
					7 years ago
						Jeffery Russell
					
					7 years ago
					
						
							committed by
							
								 GitHub
								GitHub
							
						 
					
				 
				
			 
		 
		
			
				
				  
				  No known key found for this signature in database
				  
				  	
						GPG Key ID: 4AEE18F83AFDEB23
				  	
				  
				
			
		
		
		
	
		
			  1 changed files with 
16 additions and 
0 deletions
			
		 
		
			
				- 
					
					
					 
					sorting/selectionsort.py
				
					
					
						
							
								
									
										
											
												
	
		
			
				
					|  |  | @ -0,0 +1,16 @@ | 
			
		
	
		
			
				
					|  |  |  | #selection sorting | 
			
		
	
		
			
				
					|  |  |  | import sys | 
			
		
	
		
			
				
					|  |  |  | A = [6, 2, 1, 3, 4] | 
			
		
	
		
			
				
					|  |  |  | for i in range(len(A)): | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | min_index = i | 
			
		
	
		
			
				
					|  |  |  | for j in range(i+1, len(A)): | 
			
		
	
		
			
				
					|  |  |  | if A[min_index] > A[j]: | 
			
		
	
		
			
				
					|  |  |  | min_index = j | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | A[i], A[min_index] = A[min_index], A[i] | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | print ("Sorted array") | 
			
		
	
		
			
				
					|  |  |  | for i in range(len(A)): | 
			
		
	
		
			
				
					|  |  |  | print("%d" %A[i]) | 
			
		
	
		
			
				
					|  |  |  |  |