Write a function to implement quicksort algorithm that will work for all types of data i.e ints, floats, chars etc.
It should accept all types of data and show the sorted data as output.
Note: This function is similar to C standard library function qsort().
First Input as a string. Input :abc cad bcd xyz bsd Output :abc bcd bsd cad xyz Second input as integer Input :5 6 4 2 3 Output :2 3 4 5 6
We use void* to implement generic quicksort function in C. void* does not know how much bytes of memory it has to occupy in memory space. It must be casted to any other data type like int*, char* before doing any operation on it.
Example: when we declare int var; compiler knows that it has occupy 4 bytes of memory but void does not know how much bytes of memory it has to occupy.
We will also use a pointer to function that will point to a function which is dependent to different types of data i.e and this function will be defined by the user according to there need.
Below is the image representation of void* in memory before and after casting it to any particular data type for better understanding.
Void* pt in Memory :
void* pt casted to char* :
afg bbc def ede hello hmmm how okay xcd 23 44 45 65 70 78 89
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.