Hi, I've been struggling to find the problem in my code for quicksorting a list from an input file. It gets stuck in and endless loop displaying strange numerical values. I've lost what's going on as its something i've returned to
Good question. I don't know. But I would think that Sort() use a call to qsort() to sort a string in alphabetic order. That's a google question. I have been using qsort to sort random numbers and it works great. After been going through google about all the sorting ways it came out that quick sort is the best all around sorting way.
When you copy code to your question then highlight it and go on the right side in format and select <>. That will set your file up right. It's tough to read without all the right tabs/spaces.
@Gaminic:
Found it on google. Seem like sort() is better than qsort(). I'm getting old. Ha Ha
sort() can be compared to the qsort() function in the C standard library (in stdlib.h). sort is templated, so it uses the correct comparison function for whatever data type you are sorting, which is already implemented for standard data types. Otherwise you can specify your own comparison function, which can be type-checked by the compiler; whereas for qsort, you must manually cast pointers to the desired type in an unsafe way. Also, qsort accesses the comparison function using a function pointer, necessitating large numbers of repeated function calls, which can take a lot of time; whereas in C++, comparison functions are usually inlined, removing the need for function calls. In practice, C++ code using sort is often many times faster at sorting simple data like integers than equivalent C code using qsort.