排序算法
2021-03-28 09:26
标签:data fine mil 冒泡排序 线性时间 lse 10个 iostream art 十种常见排序算法可以分为两大类: 摘自https://www.cnblogs.com/onepixel/articles/7674659.html 如下只有冒泡和桶排序 /*冒泡算法测试*/ #include "stdafx.h" #define uint unsigned int /*打印排序结果*/ /*测试排序顺序*/ /*桶排序*/ for (int i = 0; i for (int i = 0; i } int64_t getCurrentTime() void rand_m(uint num, int *buff) re_seq1(NUM_R,buf); } 排序算法 标签:data fine mil 冒泡排序 线性时间 lse 10个 iostream art 原文地址:https://www.cnblogs.com/xiuyaa/p/13635992.html
/*产生随机整数--int32 10个*/
/*排序*/
/*检测排序结果*/
#include
#include
#include
#include
#include
#include
using namespace std;
#define int64_t long long
#define NUM_R 10
#define TONG 255
void print_buf(uint num, int *buf)
{
uint i;
printf("after data:");
for (i = 0; i printf("%d ", *buf++);
printf("\n");
}
int test_seq(uint num, int *buff)
{
uint i;
for (i = 0; i {
if (*buff buff++;
else
return -1;
}
return 0;
}
/*冒泡排序*/
void swap_func(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void re_seq1(uint num, int *buff)
{
uint i, j;
uint re_q = num - 1;
for (i = 0; i {
for (j = 0; j {
if (buff[j] > buff[j + 1])
swap_func(&buff[j], &buff[j + 1]);
else
;
}
}
}
void TongSort(int num,int *score)
{
int a[TONG + 1] = {0};
int temp = score[i];
a[temp]++;
}
int num_print = a[i];
for (int j = 1; j {
*score = i;
score++;
}
}
{
struct timeb rawtime;
ftime(&rawtime);
return rawtime.time * 1000 + rawtime.millitm;
}
{
int i = 0;
printf("随机数:");
for (; i {
srand((uint)getCurrentTime());
*buff = rand() % TONG;
printf("%d ", *buff);
buff++;
Sleep(10);
}
printf("\n");
}
int main(int argc, char ** argv)
{
printf("******排序测试*******\n");
int buf[100] = { 0 };
int res = 0;
if (NUM_R > 100)
{
printf("err NUM_R \n");
return -1;
}
rand_m(NUM_R, buf);
//TongSort(NUM_R, buf);
res = test_seq(NUM_R, buf);
if (res printf("\n****err*****\n");
print_buf(NUM_R, buf);
system("PAUSE");
上一篇:100. 相同的树(C++)