Delan Azabani
Delan Azabani

Reputation: 81384

Quicksort implementation in C?

I really like the qsort function in C. It's so easy to use and allows me to procrastinate learning C++ template types. I have a few questions about this:

Upvotes: 2

Views: 983

Answers (1)

James McNellis
James McNellis

Reputation: 355049

Is the algorithm used always a quicksort or is it compiler-implementation-dependent?

It is implementation dependent.

Would you recommend using this function or is there a real benefit to templates?

C does not have templates. If you need a generic sorting function in C, then qsort is a good choice.

If you are going to use C++, then you should use std::sort, which is much easier to use correctly and gives type safety.

Are there any things I should watch out for to avoid security problems/segfaults?

If you use the function improperly (for example, if you pass it incorrect parameters or if your comparison function has bugs in it), then your program might well crash (or might otherwise perform incorrectly). Of course, this isn't specific to qsort; this is true for anything used in a program.

Upvotes: 5

Related Questions