作者shmm (有要念书找找我)
看板ESOE-91
标题计程实习回顾3
时间Sun Jun 15 23:11:31 2003
※ [本文转录自 ESOE-91 看板]
作者: shmm (我要电小堡) 看板: ESOE-91
标题: 小堡 我计程跟你讲的
时间: Thu May 8 02:24:04 2003
#include <stdio.h>
#include <stdlib.h>
int* my_sort(int* num,int n);
int main()
{
int *num,n,i;
printf("总共数目: ");
scanf("%d",&n);
num=(int*)calloc(n,sizeof(int));
for(i=0;i<n;i++)
{
printf("第%2d个数: ",i+1);
scanf("%d",(num+i));
}
num=my_sort(num,n);
for(i=0;i<n;i++) printf("%d ",*(num+i));
printf("\n");
return 0;
free(num);
}
int* my_sort(int* num,int n)
{
int *sort,i,j,count;
char *check;
sort=(int*)calloc(n,sizeof(int));
check=(char*)calloc(n,sizeof(char));
for(i=0;i<n;i++)
{
for(count=0,j=0;j<n;j++)
if(*(num+i)>*(num+j)) count++;
for(;*(check+count)=='d';count++);
*(sort+count)=*(num+i);
*(check+count)='d';
}
return sort;
free(sort);
free(check);
}
这理论上比泡泡快很多
实际上我没试
只前有po的因为有数字重复会变0的情形
所以我自D了
改成多用一个 check 来检查
不小心看到的请更正
--
※ 发信站: 批踢踢实业坊(ptt.csie.ntu.edu.tw)
◆ From: 140.112.240.76
※ 编辑: shmm 来自: 140.112.240.76 (05/08 02:24)
※ 编辑: shmm 来自: 140.112.240.76 (05/08 02:25)
--
※ 发信站: 批踢踢实业坊(ptt.csie.ntu.edu.tw)
◆ From: 140.112.26.85