Equivalent C code for templatized C++ -


here bubble sort function wrote:

template <class iter> void bubble_sort(iter begin, iter end, int (*cmp)(void *, void *)) {     bool didswap;     {         didswap = false;         (iter temp = begin; (temp + 1) != end; ++temp)             if ((*cmp)((temp+1), (temp))) {                 std::swap(*(temp+1), *temp);                 didswap = true;             }         --end;     } while (didswap); } 

i wondering if possible such thing done in c. comparison function works fine long not used standard stl containers such deque, vector, list, etc. iter begin , iter end worried about. since cannot pointer arithmetic void, how can accomplish this? possible this?

you way qsort function it, , pass size type , size of array, pointer start of array.

void bubble_sort(void* begin, size_t num, size_t size, int (*cmp)(void*,void*)); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -