![]() |
#1 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2004
Location: Nootdorp, Netherlands
Posts: 226
|
![]() I'm looking for a fast sorting algorythm to alphabetically sort a list from A to Z.
Code:
Dim Title() as String, NumOfTitles as Long Dim Temp as String Dim I as Long, J as Long Code:
For I = 1 To NumOfTitles *For J = 1 To NumOfTitles * *If LCase(Title(I)) < LCase(Title(J)) Then * * *Temp = Title(I) * * *Title(I) = Title(J) * * *Title(J) = Temp * *End If *Next J Next I |
||
![]() ![]() |
|
![]() |
#2 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2005
Location: ,
Posts: 454
|
![]() Did you try "Quick Sort"
__________________
Never mess with me when I have a cougar, Never! |
||
![]() ![]() |
|
![]() |
#3 | ||
![]() ![]() ![]() ![]() |
![]() Koen, look at your code. You have an outer loop on I and an inner loop on J, both of which run from 1 to the size of your input. Then you have a compare and 3 assignments. These don't matter, but the two nested loops give your code a time complexity of O(n^2), which means that for any input, your algorithm will take the quadratic of the input to complete. This is very bad, save for the smallest of inputs.
You might want to consider implementing Quicksort, which has an average case of O(n log(n)), and a worst case of O(n^2), but this can be made exponentially unlikely with a well chosen pivoting strategy. You should consult a good book on algorithms and data structures. If your inputs will never be too big, you might also consider Shellsort or Mergesort. I hope this helps. EDIT: Recursive algorithms are not very efficient for small datasets due to the cost of recursion, so you might want to switch to a nonrecursive strategy to sort the last 20 - 30 elements in your set. |
||
![]() ![]() |
|
![]() |
#4 | ||
![]() ![]() ![]() Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
![]() Sorting algorithms. There's Quick Sort in there, with a full explanation and example sourcecode. Besides the Quick Sort algorithm, there're all the others, too.
|
||
![]() ![]() |
|
![]() |
#5 | ||
![]() ![]() ![]() ![]() |
![]() Kon-Tiki, the example Quicksort source code you link to uses the leftmost element as the pivot, which could lead to disastrous results.
Imagine feeding sorted input to the algorithm. Then, because of the partitioning strategy, all elements will end up in the same half of the array. Worse, this happens consistently through the recursion, so the algorithm will take quadratic time to do nothing at all! Furthermore, input with largely sorted parts can be quite frequent in real life. This implementation is not recommended. Median-of-three partitioning should be used instead. That's why not having some understanding of what's going on can actually harm you. |
||
![]() ![]() |
|
![]() |
#6 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2005
Location: ,
Posts: 454
|
![]() WOW............................................... .................yes.............................. :blink:
Admit Koen that you wasn't expecting this.
__________________
Never mess with me when I have a cougar, Never! |
||
![]() ![]() |
|
![]() |
#7 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2005
Location: Shella, Kenya
Posts: 710
|
![]() I am such a geek.
Once, in university, I was working on coding some stupid exercise or another, and my friend was sitting next to me, working on coding a graph that visually displayed the various sorting algorithm efficiencies... He turned to me and said, "Something's just not right. What do you think?" I looked at the screen, and the graph was most definitely not displaying correctly. Lines were going out of the margins, were not behaving according to the actual algorithms, etc. I turned to my friend with a straight face and said: "Well... it's a graph... of sorts..." (If you get this, and laugh, you deserve to be locked up just as much as I do.) Edit: Sorry about the |
||
![]() ![]() |
|
![]() |
#8 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2004
Location: Nootdorp, Netherlands
Posts: 226
|
![]() Quote:
I'm using it for my random mp3 player to sort all files alphabetically. This can be on title, artist, album, key or bpm. The mp3 player was loading a bit slow, and in fact the only reason was that it was sorting all files, and I didn't expect that to work so slow... Thanks for the reactions EDIT. Found and example in VB, and for those who want to know it too: http://www.vba-programmer.com/Word_Code/Qu...e_Dimension.txt |
||
![]() ![]() |
|
![]() |
#9 | ||
![]() ![]() ![]() Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
![]() It's strange that that link doesn't work. Just tested it again, and it does work here.
|
||
![]() ![]() |
|
![]() |
#10 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2005
Location: ,
Posts: 454
|
![]() Works for me to.
I could save the page so you could download it if you still can't open the link.
__________________
Never mess with me when I have a cougar, Never! |
||
![]() ![]() |
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Game Sorting Sugestion.. | LingonKungen | Old Suggestions | 9 | 13-06-2007 06:41 AM |
Fastest Ever Beated A Game? | Mr.Snuggles | Gaming Zone | 46 | 14-11-2005 11:08 PM |
Sorting Options | eric10051981 | Old Suggestions | 1 | 17-06-2004 09:18 AM |
Thread Tools | |
Display Modes | |
|
|
||
  |