📄 sortnum.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/timeb.h>
typedef int KeyType;
#include "Sort.h"
#define MaxSize 80
typedef DataTypeSort DataType;
#include "SeqList.h"
#include "SLNode.h"
int FindSameNum(SLNode *L,SLNode *G)
{
SLNode *p,*q;
p=L->next;
int SameNum=0;
while(p!=L)
{
q=G->next;
p=p->next;
while(q!=G)
{
if((q->data.key)==(p->data.key))SameNum++;
q=q->next;
}
}
return SameNum;
}
/////////////////////////////////////1.两列整数在顺序存储方式中////////////////////////////////////
void Sorttime()
{
int min,max,count,i,j;
printf("\n\n\n 请输入数的个数大于10000以上,数值范围相差100以上\n\n\n");
CRNum(&count);
RNum(&min,&max);
srand((unsigned)time(NULL));
DataType *a,*b;
if ((a=(DataTypeSort *)malloc(count*sizeof(DataTypeSort)))==NULL)
{
printf("错误!\n");
exit(0);
}
if ((b=(DataTypeSort *)malloc(count*sizeof(DataTypeSort)))==NULL)
{
printf("错误!\n");
exit(0);
}
srand((unsigned)time(NULL));
for (i=0;i<count;i++) //伪随机生成随机数(也就是根据系统时间随机)
{
a[i].key=rand()%(max-min)+min;
}
_timeb beginms,endms;
int bgin,end;
int utime;
for(i=1;i<8;i++)
{
for (j=0;j<count;j++)
{
b[j].key=a[j].key;
}
bgin=(unsigned)time(NULL);
_ftime(&beginms);
SelectSort(i,b,count);
end=(unsigned)time(NULL);
_ftime(&endms);
utime=(end-bgin)*1000+endms.millitm-beginms.millitm;
printf("数组排序算法所需要实际时间为: %d ms\n\n\n",utime);
}
free (a);
free (b);
}
void main()
{
int end=1;
while(end==1)
{
Sorttime();
printf ("\n\n___________再运行多一次?________________\n");
printf("1.YES\n");
printf("2.NO\n");
printf("(输入以上序号)选择: ");
scanf("%d",&end);
system("cls");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -