Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Sorter (http://www.programmingforums.org/showthread.php?t=237)

sunnylearns Jul 28th, 2004 1:48 AM

A generic Sorter

Ooble Jul 28th, 2004 3:06 AM

And what a great tutorial that was :P

kurifu Jul 28th, 2004 5:03 AM

Quick sort is fun :) Not so easy to work with though if you want a stable sort of course... though it is possible if I recall correctly.... actually now that I think about it, it really is not difficult to implement.

Shell sorts are just... nasty... I hate them, and merge sort, well they are alright, but I do not like the way the recurse ;)

Mjordan2nd Jul 28th, 2004 7:19 AM

I'm guessing he's looking for a sort method. Since this is not a tutorial, it has been moved to the Java section from the Java tutorial section.

Pizentios Jul 28th, 2004 8:38 AM

looks to me that he just wants us to do it for him.

Infinite Recursion Jul 28th, 2004 8:47 PM

No idea what this is all about... But gotta love the recursion; hence, the name.

ASBands Jul 29th, 2004 12:47 AM

Bubble Sort all the way!

Just kidding!

But here are two methods for bubble sort with strings...pretty generic...

:

static void BubbleSortRecurse(String[] s){
 for (int i = 0; i < s.length - 1; i++){
        if (s[i].compareTo(s[i + 1]) >= 0.0){
  String temp = s[i + 1];
  s[i + 1] = s[i];
  s[i] = temp;

  BubbleSortRecurse(s);
        }
 }
        }
       
        static void BubbleSortRegular(String[] s){
 for (int i = 0; i < s.length; i++){
        for (int j = 0; j < s.length - i - 1; j++){
  if (s[j].compareTo(s[j + 1]) >= 0.0){
          String temp = s[j + 1];
          s[j + 1] = s[j];
          s[j] = temp;
  }
        }
 }
        }


kurifu Jul 30th, 2004 12:11 AM

haha, bubble sort works... but the convergence on it is NASTY! O(N)^2 is not fun to deal with when working with really large datasets (and yes I have, lol).

Quicksort, that is the way to go :) A little tricky to implement (not as bad a merge sort) but the convergence on it is insane (do not remember it off the top of my head), probably something near O(n).

Infinite Recursion Jul 30th, 2004 7:47 AM

Quick sort is probably top notch... but if I am not mistaken there is a faster sorting algorithm available, I do not recall its name. I wouldn't mind trying to make one of my own. :)

kurifu Jul 30th, 2004 12:04 PM

The only sort I know of that is faster then quick sort is heap Sort. The C++ STL uses a mix of heap sort (non stable) and quick-sort (stable) sorts.

There could be something faster I do not know about though, which is very possible.


All times are GMT -5. The time now is 10:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC