Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "header.h"
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void sort(void *base, size_t nmemb, size_t size,
- int (*compare)(const void *, const void *))
- {
- if(!compare) return;
- if(base == NULL) return;
- if(size < 2) return;
- for(int i = 0; i < nmemb - 1; i++)
- for(int j = 0; j < nmemb -1 - i; j++)
- {
- char *a = (char*)base + size*j,
- *b = (char*)base + size*(j+1);
- if(compare(a, b) > 0)
- {
- for(int k = 0; k < size; k++)
- {
- char temp = *(a+k);
- *(a+k) = *(b+k);
- *(b+k) = temp;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement