![]() ![]() After each pass you could check the flag. To be able to skip future iterations once sorted, you would need to add a flag if an unsorted pair of neighbors was found, and then each pass, you would need to check, for each element whether each pair of neighbors was sorted. However, you could try to optimize the algorithm by checking to see if the array was sorted. With selection sort, you have to go through all the iterations (the algorithm has no way of knowing if the array is sorted before it has done all the iterations). ![]()
0 Comments
Leave a Reply. |