开发者

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:

  • Is the algorithm used always a quicksort or is it compiler-implementat开发者_StackOverflowion-dependent?
  • Would you recommend using this function or is there a real benefit to templates?
  • Are there any things I should watch out for to avoid security problems/segfaults?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜