selection sort java

Solutions on MaxInterview for selection sort java by the best coders in the world

showing results for - "selection sort java"
Ivan
20 Apr 2020
1public static void SelectionSort(int[] arr)
2{
3  int small;
4  for (int i = 0; i <arr.length - 1; i++)
5  {
6    small = i;
7    for (int j = i + 1; j < arr.length; j++)
8    {
9      //if current position is less than previous smallest
10      if (arr[j] < arr[small])
11      {
12        small = j;
13        
14        //swap values
15        int temp = arr[i];
16        arr[i] = arr[small];
17        arr[small] = temp; 
18      }
19  	}
20  }
21}
Cedric
06 Sep 2018
1// example on selection sort java
2public class SelectionSortInJava
3{
4   void toSort(int[] arrNum)
5   {
6      int number = arrNum.length;
7      for(int a = 0; a < number - 1; a++)
8      {
9         // finding minimum element
10         int minimum = a;
11         for(int b = a + 1; b < number; b++)
12         {
13            if(arrNum[b] < arrNum[minimum])
14            {
15               minimum = b;
16            }
17         }
18         // swapping minimum element with first element
19         int temp = arrNum[minimum];
20         arrNum[minimum] = arrNum[a];
21         arrNum[a] = temp;
22      }
23   }
24   // printing array
25   void displayArray(int[] arrPrint)
26   {
27      int num = arrPrint.length;
28      for(int a = 0; a < num; ++a)
29      {
30         System.out.print(arrPrint[a] + " ");
31      }
32      System.out.println();
33   }
34   public static void main(String[] args)
35   {
36      SelectionSortInJava obj = new SelectionSortInJava();
37      int[] arrInput = {5, 4, -3, 2, -1};
38      obj.toSort(arrInput);
39      System.out.println("After sorting : ");
40      obj.displayArray(arrInput);
41   }
42}
Pietro
21 May 2016
1static void selectionSort(int[] arr) {
2        int lowest, lowestIndex;
3        for(int i = 0; i < arr.length -1; i++) {
4            //Find the lowest
5            lowest = arr[i];
6            lowestIndex = i;
7            for(int j = i; j < arr.length; j++) {
8                if(arr[j] < lowest) {
9                    lowest = arr[j];
10                    lowestIndex = j;
11                }
12            }
13            //Swap
14            if(i != lowestIndex) {
15                int temp = arr[i];
16                arr[i] = arr[lowestIndex];
17                arr[lowestIndex] = temp;
18            }
19            
20        }
21    }
queries leading to this page
what is selection sort 3fsuppose you have implemented the selectionsortarray class add a method called median 28 29 to the selectionsortarray class in the selectionsortarray java program this method should return the median value in the arrayselection sort list explanation in javajava selection sort with main methodjava selection sort programselection sort codein selection sort print the index which gets swapped at each step15 29 write a program to implement selection sort using array as a data structure selection sort in ascending order javasort a set in javaselection sort program in cselection sort algorithm in javaselect sort javaselection sort in descending order in java geeks for geeksselection sort algorithm with example in javaselection sort java metodoselection sort algorithm c 2b 2b codeint selectionsort 5cselecting sort javaselection sort java return sorted arrayin place selection sort javawhat is the list after completing the first outer loop of selection sort 3ffrom selection sort import selectioninsertion sort geeksforgeeksjava array selection sortslesction sort javaselection sort coding in javahow to perform a selection sort javaselection sort java explainedsearch sort programme javaselection sort program in oops javaselection sort algoselection sorting in javaselection sort javajava program of selection sort using arraylinear sorting in javaselection sort java what isselection sort functionselection sort ajvaselection sorting algorithm in javaselection sort algorithm java exampleselection sort implementation javaselection sort jaaselection sort code javawhat is selection sort in javajava selection sort iastatevoting system using selection sortselection sort logic in javaselection sort java descedng ordersorting java selection sortselection sort jjavawhat is a selection sort in javaselection sort method javaselection sort descending order javahow to selection sort javajava selection sortsorting arrays in c 2b 2bselection sort java codesuppose you have implemented the selectionsortarray class add a method called median 28 29 to the selection sort array class in the selectionsortarray java program this method should return the median value in the arraythje code of selection sort in javavoid selectionsortselection sort with list javajava selection sortselection sort in jkavaselectionsort in javac 2b 2b selection sortselection sort array in javaselection sort program in javaselection sort in array in javaselection sort execution javaselection sorting algorithmsinplace selection sort an integer arraythe selection sort javaselection sort javaselection sort algorithm code javaselection sortselection sort list javaselection sort java int array java selection sort methodsort selectionjava selection sorthow to make a method that sorts an array of integers in ascending order by the selection sort methodselection sort auf liste javaselection sort in ccode for selection sortselection sorting javahow to use selection sort in javaselection sort method in javasort selection java4 write a program to sort the given array using selection sort java section sortwrite a program to sort an array using selection sort with time complexity algorithm for selection sort in javahow does selection sort work in java with examplselection sort in java programselection sort java simpleselection sort array javaprint selection sort swaped indexhow to make a selection sort in javaselection sort javselection sort code in javaascending order using selection sort in javaselectin sort in javamethod selection in array javasorting data by using selection sort javaselection sort explanation in javaimplement selection sort in javaslection sort in javaselection sort in javaselection sort in java programizselection sort in c 2b 2bselection sort java programming 1selection sort javaselection algorithm javaselection sort java implementationbest java programs selection sortselection sort of list javajava selection sort stringgiven a set of 4 integers 2c sort using selection sortjava selection sort codeselection sort first swapselection sort algorithm javaselection sort java algorithmsimple selection sort program in javajava sort selectionselectionsort javaselection sort passes formula javasort array with selection sort javaselection sort ascending order javajava code for selection sortselection sort java exampleselection sort in java given arrayselection sorytselection sort java programjava array selection sort functionselection sort java explanationselectkpn sort javaselecton sort code ofr javaselection sort arraysselection sort algorithm java explainedwhat is selection sorting in array javaseletion sort algorithmselection sort c 2b 2bhow does selection sort work in java with examplewhat is selection sortselection sort syntaximplement selection sort and print the index which gets swapped at each step sort array using selection sortselection sort in java with given arrayselection sort java