Skip to content

Commit

Permalink
Added SelectionSort
Browse files Browse the repository at this point in the history
  • Loading branch information
yashagldit committed Oct 3, 2018
1 parent 84bea02 commit c3939d2
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions selectionsort/java/SelectionSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class SelectionSort
{
void sort(int arr[])
{
int n = arr.length;

// One by one move boundary of unsorted subarray
for (int i = 0; i < n-1; i++)
{
// Find the minimum element in unsorted array
int min_idx = i;
for (int j = i+1; j < n; j++)
if (arr[j] < arr[min_idx])
min_idx = j;

// Swap the found minimum element with the first
// element
int temp = arr[min_idx];
arr[min_idx] = arr[i];
arr[i] = temp;
}
}

// Prints the array
void printArray(int arr[])
{
int n = arr.length;
for (int i=0; i<n; ++i)
System.out.print(arr[i]+" ");
System.out.println();
}

// Driver code to test above
public static void main(String args[])
{
SelectionSort ob = new SelectionSort();
int arr[] = {64,25,12,22,11};
ob.sort(arr);
System.out.println("Sorted array");
ob.printArray(arr);
}
}

1 comment on commit c3939d2

@sangamcse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on c3939d2.

There are 42 results for the section all.pyjava. They have been shortened and will not be shown inline because they are more than 10.

Message File Line
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 1
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 2
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 3
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 4
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 5
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 6
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 7
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 8
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 9
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 10
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 11
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 12
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 13
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 14
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 15
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 16
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 17
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 18
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 19
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 20
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 21
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 22
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 23
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 24
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 25
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 26
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 27
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 28
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 29
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 30
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 31
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 32
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 33
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 34
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 35
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 36
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 37
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 38
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 39
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 40
Line contains following spacing inconsistencies: - Trailing whitespaces. selectionsort/java/SelectionSort.java 41
Line contains following spacing inconsistencies: - No newline at EOF. - Trailing whitespaces. selectionsort/java/SelectionSort.java 42

Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.

Please sign in to comment.