Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with QuickSort

Started by CProgrammer Jan 20, 2004 at 3:25 AM 3 replies 300+ views
Original Post
CProgrammer
CProgrammer
How can I make QuickSort as a templated function. QuickSort uses integers which cant be defined as any other data type. What can I do? -CProgrammer
vesoljc
vesoljc
que?

any sort can use any data type, u only need a compare operator
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
SiCrane
SiCrane
If you''re using C++, just use std::sort(), which is almost always implemented as quicksort.
DrPizza
DrPizza
The implementations I have to hand perform an introspective sort (quicksort which switches to heapsort if it''s going quadratic), not a quicksort, and further they tend to use insertion sort for small sorts because it''s quicker.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;} /*** drpizza@battleaxe.net ***/
vaneger
vaneger
template
void quicksort(type arrayToBeSorted);
umm ya it will work just make sure the < > and = operators are defined for the given type.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.