Difference between revisions of "JavaSelectionSortAssignment.java"
From WLCS
(Created page with "<syntaxhighlight lang="Java"> public class JavaSelectionSortAssignment { public static void main( String [] args ) { int [] nums = { 604, 565, 449, 69, 869, 965,...") |
|||
Line 16: | Line 16: | ||
//Implement selection sort | //Implement selection sort | ||
+ | |||
+ | |||
+ | //HINT: Swapping elements in an array, where a and b are their indices: | ||
+ | //int tmp = arr[a] //save the element arr[a] before you overwrite it | ||
+ | //arr[a] = arr[b] | ||
+ | //arr[b] = tmp | ||
//Print the sorted array | //Print the sorted array |
Revision as of 11:23, 28 September 2016
public class JavaSelectionSortAssignment
{
public static void main( String [] args )
{
int [] nums = { 604, 565, 449, 69, 869, 965, 506, 145, 913, 874, 987, 315, 967, 543,
675, 571, 388, 167, 259, 331, 47, 863, 970, 890, 312, 109, 360, 993,
176, 490, 34, 637, 712, 721, 552, 914, 425, 551, 274, 346, 516, 922,
823, 540, 12, 53, 689, 159, 388, 285, 95, 554, 932, 755, 560, 676, 152,
912, 816, 82, 974, 518, 502, 765, 191, 176, 613, 627, 233, 995, 864,
316, 151, 169, 264, 367, 928, 841, 330, 368, 457, 843, 688, 599, 959,
67, 393, 253, 675, 46, 595, 864, 44, 425, 573, 994, 271, 781, 638, 138 };
//Print the array
//Implement selection sort
//HINT: Swapping elements in an array, where a and b are their indices:
//int tmp = arr[a] //save the element arr[a] before you overwrite it
//arr[a] = arr[b]
//arr[b] = tmp
//Print the sorted array
}
}