数据结构程序问题(急!!) 若数组a中数据按升序排列,要求将X插到表中合适位置,以保证表的有序性

来源:百度知道 编辑:UC知道 时间:2024/06/14 20:39:57
要求有C语言写啊,写出程序,并给出调试结果,
急急急!!!!!
19号早上就要了啊!
哪位大侠帮帮忙啊

#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int *key;
int length;
}node;
void insert(node &temp,int n)
{
int i,j;
for(i=0;i<temp.length;i++)
{
if(n<temp.key[i])
break;
}
temp.length++;
for(j=temp.length-1;j>i;j--)
temp.key[j]=temp.key[j-1];
temp.key[i]=n;
return ;
}
int main()
{
node a,*p;
int i,j,n;
a.length=0;
a.key=(int *)malloc(sizeof(int));
for(i=2,j=0;i<=20;i+=2,j++)

{
a.key[j]=i;
a.length++;

}
insert(a,11);
for(i=0;i<a.length;i++)
printf("%d \t",a.key[i]);
return 0;

}

当然你可以把这个结构体改为数组就OK了

frg

有关C语言数组的问题(在数组中插入一个数) 求数组int a【n】中奇数的个数和平均值以及偶数的个数和平均值(n为输入的数) 急~!! 在数组A和B中各输入10个数,输出两数组都有的数 数据结构问题:设二维数组A5*6的每个元素占4个字节,已知Loc(a00)=1000,A共占多少个字节... 从键盘输入三个数放在数组a[3]中,要求输出最大的数? 用C语言(数组)取最小数的程序 程序题,显示A数组中不等于B数组的值? 编写程序将一个数组中的数按逆序重新存放,程序中不使用辅助数组 求助C程序编程问题 ,题目:删除一维数组中所有相同的数,使之只剩下一个,数组中的数以按由小到大的顺序排列. 若有说明:int a[3][4];则数组a中各元素是()