Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first list is indeed selection sort. It is in essence the same as the algorithm on the link you’ve provided. But instead of finding the element that has the minimum value, and swapping it with
arr[i]once after thejloop, the first code immediately swapsarr[i]with any value it encounters which is smaller.In both cases, at the end of the
iloop,arr[i]will contain the smallest element in a within the rangei+1..SIZE.There are two differences between the two algorithms: the code you show here performs more than one swap per iteration, and it shuffles the data that is not yet sorted (this is not really important, as they will eventually get sorted). So, basically it is less efficient than the code you’ve linked.