下面是我实验的方法,时间复杂度为o(n)
#include
#include
int sort(char arry[],int n)
{
int i=0;
int max = arry[0];
int second;
for(i=1;i {
if(max <= arry[i])
{
second = max;
max = arry[i];
}
else
{
if(second <=arry[i])
{
second = arry[i];
}
}
}
return second;
}
int main()
{
char a[10]={34,54,115,32,30,55,27,34,118};
int n = strlen(a);
int p = sort(a,n);
printf("the second biggest number is %d\n",p);
return 0;
}
阅读(2621) | 评论(0) | 转发(0) |