Suppose you have implemented the SelectionSortArray class. Add a method called median() to the Selection Sort Array class in the SelectionSortArray.java program. This method should return the median value in the array code example

Example: selection sort in java

public static void SelectionSort(int[] arr)
{
  int small;
  for (int i = 0; i <arr.length - 1; i++)
  {
    small = i;
    for (int j = i + 1; j < arr.length; j++)
    {
      //if current position is less than previous smallest
      if (arr[j] < arr[small])
      {
        small = j;
        
        //swap values
        int temp = arr[i];
        arr[i] = arr[small];
        arr[small] = temp; 
      }
  	}
  }
}

Tags:

Cpp Example