Java - Selection Sort Algorithm

后端 未结 17 1641
我在风中等你
我在风中等你 2020-12-17 04:26

I have some questions about selection sort.I\'m a little bit confused.

 int [] arr = {5,4,3,2,1}; // This is my array
    int min = 0;

    for(int i = 0;i&l         


        
17条回答
  •  佛祖请我去吃肉
    2020-12-17 04:58

    Your question appears to be in your comment

    min = i;//Selection sort algorithm says that find the minimum in the
            // array, but first element is not minimum.What's point here?
    

    The point of that is you can assume the first one you're checking is the lowest just so you have a place to start from. After all, it might not be the minimum over all, but of the one's you've checked in this iteration, it's the lowest so far!

提交回复
热议问题