0

Can someone explain this sort algorithm to me and how i can make a more efficient version, justifying the changes.

for (int p = 0; p<n-1; p++)
for (int counter = 0;counter < n-1; counter++)
if (a[counter]> a[counter+1])
swap(a, counter, counter+1);

Apreciate all help.

5
Contributors
5
Replies
6
Views
12 Years
Discussion Span
Last Post by jwenting
0

Infact there are many sort algorithms, e.g., bubble sort, quick sort, merge sort. And this is bubble sort. In this algorithm there are maximum number of comparison. So use some other algorithm for sorting.
and reply my e-mails :-)

0

Depending on the application of your sort, a radix sort might also be considered. Though not the most efficient for smaller arrays, I hear its the fastest for very large arrays. The quick sort works pretty well and fast, and its rather easy to understand so its probably your best bet to look into that.

0

Which sorting algorithm is the most efficient depends on what is being sorted and how random (compared to the sorted state) the initial data is.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.