Quick sort

WBahn

Joined Mar 31, 2012
30,074
There example is for numbers.

In general, all you need to sort any list is a means of deciding whether item A is "greater" than item B.

When you use their code as is and without any modification at all, what do you get?
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
There example is for numbers.

In general, all you need to sort any list is a means of deciding whether item A and "greater" than item B.

When you use their code as is and without any modification at all, what do you get?

OP said using "algorithm" . That suggests to me that OP is not using actual code but just the algorithm of the code. Could be any language and yes including C#.
 

WBahn

Joined Mar 31, 2012
30,074
Good point.

All the more important to post the actual code -- well presented and commented -- so that we don't have to use our crystal balls to read his mind.
 

amilton542

Joined Nov 13, 2010
497

WBahn

Joined Mar 31, 2012
30,074
Because q-sort is primarily a string based algorithm.
Q-sort is essentially a generic algorithm. IIRC correctly (and it has literally been decades since I used it) the qsort function in the standard C library requires you to supply a pointer to a function that takes two arguments and returns an integer value that is <0, 0, or >0 depending on the relative order that the two items should be placed in. This is one of the reasons for the nature of the output of the strcmp() family of functions.
 

amilton542

Joined Nov 13, 2010
497
The reason why I said that (and how unqualified I am to be even contributing in this subset of a forum) is that I was writing code one day to sort numbers alone and I was trying to apply the same techniques but to strings and the guy just said that will never work you need to use the q-sort algorithm if that's what you're trying to achieve and the chap I am I just took his word for it.
 

djsfantasi

Joined Apr 11, 2010
9,163
The error the TS is getting is "StackOverFlowException". He doesn't state which algorithm from that link he is using, but I note that one is a recursive algorithm. If that is what he is using, and depending on the actual data being sorted (which determines the number of recursions) and depending on what platform (memory restrictions) - recursion lends itself to stack overflows. Again, not enough information and the TS hasn't returned yet. As WBahn stated, I would like to see the code and his data in addition.
 

WBahn

Joined Mar 31, 2012
30,074
The reason why I said that (and how unqualified I am to be even contributing in this subset of a forum) is that I was writing code one day to sort numbers alone and I was trying to apply the same techniques but to strings and the guy just said that will never work you need to use the q-sort algorithm if that's what you're trying to achieve and the chap I am I just took his word for it.
A good way to learn is to engage in a discussion and put forth your best ideas and believes and have them be challenged and corrected.
 
Top