#Selectionsort

1 messages · Page 1 of 1 (latest)

delicate vigil
#

I am really struggling with selectionsort and don't understand the codes i get when googling for a selectionsort method.

lucid mountainBOT
#

This post has been reserved for your question.

Hey @delicate vigil! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

delicate vigil
#
import java.util.Arrays;
public class sauce{
    public static void main(String[] args) {
    int[] a = {5, 4, 3, 2, 1};
    for(int i = 0; i < (a.length-1); i++){
        int indexmaxvalue = i;
        int tobetested = a[i];
            if(tobetested > indexmaxvalue){
                indexmaxvalue = tobetested;
            }
        a[a.length-1-i] = indexmaxvalue;
    }
    System.out.println(Arrays.toString(a));
}
}
#

this is what i got up until now but the output is [5, 4, 3, 4, 5]

#

also it's supposed to be in ascending order

cedar stream
#

you're only doing half of the swap

delicate vigil
#

wait i'll try again with the min and let you know if i got it right this time

#

thanks for yourhelp

cedar stream
#

also, consider that you have 2 kinds of values that you're working with

#

you have elements of the array, and you have indexes of the array.

#

with selection sort, you only need to compare elements.

#

indexes should never show up in comparisons within selectionsort, and indexes should never be compared with elements unless they already have some other special meaning

#

you're mixing indexes and elements

delicate vigil
#

ok imma give up on the selection sort thing and just try to get the damn thing working lol

#

but thanks alot for your help