This week's book giveaway is in the
General Computing
forum.
We're giving away four copies of
Arduino in Action
and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
java swap in selectionsort
chris rous
Greenhorn
Joined: May 16, 2012
Posts: 21
I like...
posted
May 18, 2012 05:36:27
0
package sortieren; public class selectionSort { static void selectionsort(int[] a){ int high = a.length -1; for(int k =0; k<high; k++){ int min= minPos(a, k, high); if (min != k) swap(a, min, k); }} private static void swap(int[] a, int min, int k) { } private static int minPos(int[] a, int low, int high) { int min= low; for(int i= low +1; i<=high; i++) if(a[i]<a[min]) min=i; return min; } public static void main(String[] args) { int liste[] = {8, 1, 3, 2, 9, 100, 88, 73, 3, 4, 94, 85, 38, 58, 40, 95}; selectionsort(liste); for (int i=0; i<liste.length; i++) System.out.print(liste[i]+" "); } }
could someone help me out with how the swap should look for my selection sort?
chris rous
Greenhorn
Joined: May 16, 2012
Posts: 21
I like...
posted
May 18, 2012 05:40:51
0
nvm i got it
package sortieren; public class selectionSort { static void selectionsort(int[] a){ int high = a.length -1; for(int k =0; k<high; k++){ int min= minPos(a, k, high); if (min != k) swap(a, min, k); }} private static void swap(int[] a, int min, int k) { int temp =a[min]; a[min]=a[k]; a[k]=temp; } private static int minPos(int[] a, int low, int high) { int min= low; for(int i= low +1; i<=high; i++) if(a[i]<a[min]) min=i; return min; } public static void main(String[] args) { int liste[] = {8, 1, 3, 2, 9, 100, 88, 73, 3, 4, 94, 85, 38, 58, 40, 95}; selectionsort(liste); for (int i=0; i<liste.length; i++) System.out.print(liste[i]+" "); } }
I agree. Here's the link:
http://aspose.com/file-tools
subject: java swap in selectionsort
Similar Threads
help with sort code
bubblesort
does this sort an array of integers?
method overloading in sort program
Comparing one array to another
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter