# 那些年，那些值得珍藏的算法

Int16位整数字节交换，简单移位运算后或运算

static inline uint16_t bswap_16(uint16_t x)

{

return (x >> 8) | (x << 8);

}

int32位长整型字节交换

static inline uint32_5 bswap_32(uint32_t x)

{

x = ((x << 8) &0xFF00FF00) | ((x>>8)&0x00FF00FF);

return (x >> 16) | (x << 16);

}

#define DECL_FUNCINTRO(call,ret,name,args) \

typedef ret (call *name ## _func) args; \

ret call new_ ## name args; \

extern  name ## _func orig_ ## name; \

extern  name ## _func load_ ## name;

{ \

if(hDll) { \

} \

}

void bubble_sort(int a[],int n)

{

for(int i = 0;i<n-1;i++)

{

for(int j = 0;j<n-1-i;j++)

{

if(a[j] > a[j+1])

{

int temp =a[j]; a[j] = a[j+1];a[j+1]=a[j];

}

}

}

}

int partition(int *data,int low,int hign)

{

int t = 0;

t = data[low];

while(low < high)

{

while(low < high && data[high] >= t)

high --;

data[low] = data[high];

while(low < high && data[low] < t)

low++;

data[high] = data[low];

}

data[low] = t;

return low;

}

void quick_sort(int *data,int low,int high)

{

if(low <= high) return;

int pivotloc = 0;

pivotloc = partition(data,low,high);

quick_sort(data,low,pivotloc-1);

quick_sort(data,pivotloc-1,high);

}

void quick_sort(int s[],int l,int r)

{

if(l< r)

{

int i = l,j= r,x=s[l];

while(i < j)

{

while(i<j && s[j] >= x)

j--;

if(i < j)

s[i++] = s[j];

while(i < j && s[i] < x)

i++;

if(i < j)

s[j--] = s[i];

}

s[i] = x;

quick_sort(s,l,i - 1);

quick_sort(s,i+ 1,r);

}

}

static void selection_sort(int a[],int n)

{

for(int i = 0;i<n;i++)

{

int min = a[i],min_index = i;

for(int j = i;j<n;j++)

{

if(a[j] < min)

{

min = a[j];

min_index = j;

}

}

if(min_index != i)

{

int temp = a[i];

a[i] = a[min_index];

a[min_index] = temp;

}

}

}

void heap_sort(int a[],int i)

{

int j ,temp;

temp = a[i];

j = (i - 1) /2;

while(j >= 0 && i != 0)

{

if (a[j] <= temp) break;

a[i] = a[j];

i = j;

j = (i - 1)/2;

}

a[i]  = temp;

}

• 本文已收录于以下专栏：

举报原因： 您举报文章：那些年，那些值得珍藏的算法 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)