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; 
      }
  	}
  }
}

0
0
Awgiedawgie 440220 points

                                    static void selectionSort(int[] arr) {
        int lowest, lowestIndex;
        for(int i = 0; i &lt; arr.length -1; i++) {
            //Find the lowest
            lowest = arr[i];
            lowestIndex = i;
            for(int j = i; j &lt; arr.length; j++) {
                if(arr[j] &lt; lowest) {
                    lowest = arr[j];
                    lowestIndex = j;
                }
            }
            //Swap
            if(i != lowestIndex) {
                int temp = arr[i];
                arr[i] = arr[lowestIndex];
                arr[lowestIndex] = temp;
            }
            
        }
    }

0
0
4.2
5
Awgiedawgie 440220 points

                                    // example on selection sort java
public class SelectionSortInJava
{
   void toSort(int[] arrNum)
   {
      int number = arrNum.length;
      for(int a = 0; a &lt; number - 1; a++)
      {
         // finding minimum element
         int minimum = a;
         for(int b = a + 1; b &lt; number; b++)
         {
            if(arrNum[b] &lt; arrNum[minimum])
            {
               minimum = b;
            }
         }
         // swapping minimum element with first element
         int temp = arrNum[minimum];
         arrNum[minimum] = arrNum[a];
         arrNum[a] = temp;
      }
   }
   // printing array
   void displayArray(int[] arrPrint)
   {
      int num = arrPrint.length;
      for(int a = 0; a &lt; num; ++a)
      {
         System.out.print(arrPrint[a] + &quot; &quot;);
      }
      System.out.println();
   }
   public static void main(String[] args)
   {
      SelectionSortInJava obj = new SelectionSortInJava();
      int[] arrInput = {5, 4, -3, 2, -1};
      obj.toSort(arrInput);
      System.out.println(&quot;After sorting : &quot;);
      obj.displayArray(arrInput);
   }
}

4.2 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
selection sort java example selection sort explanation in java selection sort list explanation in java selection sort jaa selection sort logic in java thje code of selection sort in java Selection Sort. java selection sort in java programiz what is selection sorting in array java selection sort java what is java program of selection sort using array selection sort jav selection sort algorithm java explained selection sort in java program selection sort list java java code for selection sort how does selection sort work in java with example how does selection sort work in java with exampl sorting data by using selection sort java simple selection sort program in java selection sort jjava java Selection.sort algorithm for selection sort in java selection sort ajva selection sort java descedng order selection sort method in java selection sort java explanation ascending order using selection sort in java selection sort in java given array java selection sort method selection sort java selection sort with list java selection sort java programming 1 selection sort algorithm code java selection sort code in java java sort selection selection sort java explained java array selection sort selection sort descending order java selection sorting algorithm in java how to use selection sort in java method selection in array java What is selection sort? void selectionsort selecton sort code ofr java the selection sort java selection sort java metodo selection sort in java with given array How to make a method that sorts an array of integers in ascending order by the Selection sort method selection sort java int array java selection sort with main method java Selection sort selection sort program in c c++ selection sort sorting arrays in c++ selection sorting algorithms selection sort algorithm c++ code java selection sort string insertion sort geeksforgeeks sort array using selection sort selection sort in c selection sort first swap what is selection sort selection soryt What is the list after completing the first outer loop of selection sort? inplace selection sort an integer array 15). Write a program to implement SELECTION SORT using array as a data structure. selection sort algo seletion sort algorithm selection sort in c++ java selection sort iastate java section sort selection sort function selection sort java implementation int selectionsort\ what is selection sort in java selection sort auf liste java selection sorting java sort selection selection sort arrays selection sort in array in java selection sort algorithm java example selection sort algorithm java selection sort java return sorted array from selection sort import selection selection sort java program selectkpn sort java selection sort array in java selection sort in jkava selecting sort java java selection sort code 4. Write a program to sort the given array using Selection Sort. selection sort coding in java sort selection java sorting java selection sort selection sort program in oops java selection sort java simple selection sort of list java selection sort array java selection sort passes formula java linear sorting in java how to perform a selection sort java selection sort execution java selection sort code java selectin sort in java selectionSort in java selection sort syntax slection sort in java Implement Selection Sort and print the index which gets swapped at each step. Write a program to sort an array using selection sort with time complexity. selection algorithm java selection sort algorithm in java sort array with selection sort java selection sort java code selection sort in descending order in java geeks for geeks java array selection sort function java selection sort program selection sort code search sort programme java selectionsort java code for selection sort 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 Suppose you have implemented the SelectionSortArray class. Add a method called median() to the SelectionSortArray class in the SelectionSortArray.java program. This method should return the median value in the array selection sorting in java best java programs selection sort selection sort algorithm with example in java in place selection sort java selection sort program in java Select sort java given a set of 4 integers, sort using selection sort in selection sort print the index which gets swapped at each step print selection sort swaped index selection sort voting system using selection sort selection sort c++ sort a set in java how to make a selection sort in java selection sort method java slesction sort java java selection sort selection sort java selection sort implementation java selection sort in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source