I am working on a project which involves using several standard algorithms, like Quick Sort, Merge Sort, Binary Search. Implementing all of them before using will be very tedious and time consuming.
So, can anyone give me the list of standard algorithms already available in GCC-4.3.2., so that I can use them directly in my project.
Please comment if I am unclear in asking my doubt.
Thanks !
It’s unclear what the best answer to your question is. It could depend on what operating system you’re using.
The C standard library provides a number of functions that implement various algorithms and/or provide (limited) access to operating system features. In particular, the standard
qsort()function sorts an array, and thebsearch()function searches over an array. In both cases, the C standard specifies what they do; it says nothing about how they do it. It’s even legal for an implementation to provide aqsort()that does a Bubble Sort, and absearch()that does a linear search — though I’m sure no implementation would actually do something that silly.The definitive reference for the C standard library is the ISO C standard. There have been several successive versions of the standard, released in 1990, 1999, and 2011. A good draft of the 1999 standard is N1256; a good draft of the C11 standard is N1570. If you’re using gcc, your implementation probably implements almost all of C99 (you can use
gcc -std=c99); C11 conformance is a work in progress.Most implementations provide additional library functions that aren’t required by the C standard. For example, POSIX specifies a large number of additional functions.
The fact that you’re using gcc 4.3.2 doesn’t actually tell us what’s available in your runtime library. A C implementation consists of a compiler and a runtime library. gcc is just the compiler; depending on the OS, it can be used with a number of different runtime libraries. For Linux (or GNU/Linux if you prefer) systems, the runtime library is usually (always?) GNU libc (thanks to Jim Balter for that link). Other systems are likely use some other runtime library; you’ll have to find out what library your system uses and look up its documentation.
Note that the C library doesn’t provide a lot of general-purpose algorithms, partly because it’s difficult to express such algorithms cleanly in pure C. For example, if you look at
qsort()andbsearch(), you’ll see that they usevoid*pointers and deal with chunks of memory rather than typed objects. You might consider looking at C++, whose standard library provides a larger number of data types and algorithms; they’re more type-safe because they use C++’s template feature.