-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84bea02
commit c3939d2
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
c3939d2
There was a problem hiding this comment.
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.
Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.