#include <stdio.h>

void Swap(char* buf1, char* buf2, int width)
{
    int i = 0;
    for (i = 0; i<width; i++)
    {
        char tmp = *buf1;
        *buf1 = *buf2;
        *buf2 = tmp;
        buf1++;
        buf2++;
    }
}
void bubble_sort(void* base, int sz, int width, 
                int (*cmp)(const void* e1, const void* e2))
{
  int i = 0;
  for (i=0; i<sz-1; i++)
  {
      int j = 0;
      for (j=0; j<sz-1-i; j++)
      {
          if (cmp((char*)base+j*width, (char*)base+(j+1)*width)>0)
          {
              Swap((char*)base+j*width, (char*)base+(j+1)*width, width);
          }
      }
  }
}
int int_sort(const void* e1, const void* e2)
{
    return *(int*)e2 - *(int*)e1;
}
void print(int *arr,int sz)
{
	int i = 0;
	for (i = 0; i<sz;i++)
	{
		printf("%d ",arr[i]);
	}
}
void test1()
{
    int arr[10] = {10,1,2,3,4,5,6,7,8,9};
    int sz = sizeof(arr)/sizeof(arr[0]);
    bubble_sort(arr, sz, sizeof(arr[0]), int_sort);
	print(arr, sz);
}
int main()
{
    test1();
    
    return 0;
}