Answer to Question #283293 in Java | JSP | JSF for mmm

Question #283293

PLEASE EXPLAIN IN DETAIL HOW THIS CODE WORKS


package selectionsortexample;


public class SelectionSortExample {  

  public static void selectionSort(int[] arr){  

    for (int i = 0; i < arr.length - 1; i++)  

    {  

      int index = i;  

      for (int j = i + 1; j < arr.length; j++){  

        if (arr[j] < arr[index]){  

          index = j;//searching for lowest index  

        }  

      }  

      int smallerNumber = arr[index];  

      arr[index] = arr[i];  

      arr[i] = smallerNumber;  

    }  

  }  


1
Expert's answer
2021-12-29T02:20:10-0500

this method iterating through input array arr and searching the smallest element then placing this element to first position in array then looking for smallest element in the rest of array and placing to 2nd position and so on. In the whole this algoritm sorting array in ascending order


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog