舟山好吃的海鲜大排档:C语言函数问题

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/25 13:10:25
编写一个函数void fun(int a[],int x,int n),a数组中存放n个由大到小的有序树,函数的功能是:把x插入到a数组中,插入后的数仍然有序
我都说了一楼的不对啊,根本无法编译

你想发几遍。。
再发我可不管了
最后一次
// zd_19.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdlib.h>

int total;

void fun(int a[],int x,int n)
{
int i,j;
for(i=0;i<n;i++)
{
if(a[i]>=x && a[i+1]<=x)
{
n++;
total++;
for(j=n;j>=i;j--)
{
a[j+2]=a[j+1];
}
a[i+1]=x;
break;
}
}
}

int main(int argc, char* argv[])
{
int temp;
int num[100]={99,87,67,57,56,49,37,26,18,6};
scanf("%d",&temp);
total=10;
fun(num,temp,total);
for(int i=0;i<total;i++)
printf("%d\t",num[i]);
return 0;
}

输出:
57
99 87 67 57 57 56 49 37 26 18
6 Press any key to continue