4. Write A Program To Sort The Given Array Using Selection Sort. Code Example

Snippet 1

  public static void SelectionSort(int[] arr)
{
  int small;
  for (int i = 0; i 

             
     

Snippet 2

  # Python program for implementation of Selection 
# Sort 
import sys 
A = [64, 25, 12, 22, 11] 
  
# Traverse through all array elements 
for i in range(len(A)): 
      
    # Find the minimum element in remaining  
    # unsorted array 
    min_idx = i 
    for j in range(i+1, len(A)): 
        if A[min_idx] > A[j]: 
            min_idx = j 
              
    # Swap the found minimum element with  
    # the first element         
    A[i], A[min_idx] = A[min_idx], A[i] 
  
# Driver code to test above 
print ("Sorted array") 
for i in range(len(A)): 
    print("%d" %A[i]),  
 

Similar Snippets


Create Copy Of Array From Another Array Code Example – java

Creating Java Main Method Code Example – java

Find Duplicates In Arraylist Java Code Example – java

Java Creat A Folder Code Example – java

Firestore Find Doc And Set Data Code Example – java

Copyright © Code Fetcher 2020

 

 

Leave a comment

Your email address will not be published. Required fields are marked *