944,189 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1516
  • Java RSS
Apr 22nd, 2005
0

Can someone please help me out!!

Expand Post »
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.
Reputation Points: 13
Solved Threads: 0
Junior Poster in Training
nabil1983 is offline Offline
73 posts
since Mar 2005
Apr 22nd, 2005
0

Re: Can someone please help me out!!

More efficent?

Java Syntax (Toggle Plain Text)
  1. Arrays.sort(ArrayName);
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Apr 22nd, 2005
0

Re: Can someone please help me out!!

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 :-)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asifdahir is offline Offline
1 posts
since Apr 2005
Apr 23rd, 2005
0

Re: Can someone please help me out!!

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.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Apr 24th, 2005
0

Re: Can someone please help me out!!

Bubble sort is the most inefficent, and I believe that QuickInsertionSort is the most efficent.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Apr 25th, 2005
0

Re: Can someone please help me out!!

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: newbie... Java load large picture :) Lit'l help plez
Next Thread in Java Forum Timeline: about java servlets





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC