+ 1

Selection Sorting

Can la program of a specific sorting program differ from another program of same sorting technique? I made a program of Selection sorting after knowing its logic but I didn't find any youtube video implementing same program of selection sorting. Though my program is giving correct output, is it correct to be called selection sorting. https://code.sololearn.com/cw4Kpjin2M51/?ref=app

21st Oct 2023, 4:54 PM
Ayush Singh
Ayush Singh - avatar
6 odpowiedzi
+ 3
Yes your code does the selection sort but seems a little more complicated than it needs to be. You can find other implementations online, including Java, for example here: https://rosettacode.org/wiki/Sorting_algorithms/Selection_sort#Java My main recommendation is to choose variable names that better explain their purpose. Also there are two nested loops in this algorithms. Inside the first loop you make an assumption about the MIN value. You can do a little optimization by assuming the current index as the smallest, and start the inner loop from the next index. After the inner loop you can do a simple swap of the minimum value and the current value.
22nd Oct 2023, 7:53 AM
Tibor Santa
Tibor Santa - avatar
+ 1
i cant Open your Code can you try to clicke on the plus and add your code
21st Oct 2023, 8:27 PM
D1M3
D1M3 - avatar
+ 1
implementation of the sorting algorithm can include smaler variations and optimization of the main idea correct link is https://code.sololearn.com/cw4Kpjin2M51/?ref=app
22nd Oct 2023, 3:23 AM
zemiak
+ 1
I am Not very good at Java But i Made it in c++. If it helps i could give you my Code in c++
22nd Oct 2023, 8:32 AM
D1M3
D1M3 - avatar
0
D1M3 i have inserted the code,now you can check it
22nd Oct 2023, 4:42 AM
Ayush Singh
Ayush Singh - avatar
0
D1M3 no it's ok. I got my all answers, thanks for your efforts
22nd Oct 2023, 11:47 AM
Ayush Singh
Ayush Singh - avatar