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.

More efficent?

Arrays.sort(ArrayName);

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 :-)

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.

Bubble sort is the most inefficent, and I believe that QuickInsertionSort is the most efficent.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.