给我个数据结构的程序,就是一个一个实现顺序表的添加一个数的程序!!!

如题所述

#include<stdio.h>
#define MAXLEN 100typedef int elementtype;
typedef struct
{
elementtype s[MAXLEN];
int len;
}SqList;int insertsqlist(int i,elementtype x, SqList *sql)
{
int j;
if((i<1)||(i>sql->len))
return 0;
else
{
for(j=sql->len;j>=i;j--)
sql->s[j+1]=sql->s[j];
sql->s[j+1]=x;
(sql->len)++;
return(1);
}
}void main()
{
int b=3,c,k;
elementtype d=9;
SqList a={0,1,2,3,4,5,6,7,8}; a.len=8;
for(k=1;k<=a.len;k++)
{
printf("%d",a.s[k]);
} printf("\n"); c=insertsqlist(b,d,&a);
if(c==0)
printf("error");
else
{
for(k=1;k<=a.len;k++)
printf("%d",a.s[k]);
}
printf("\n");
} 这个程序可以吗,貌似这种程序不难啊!!!
温馨提示:答案为网友推荐,仅供参考
相似回答