数据结构实验题c语言描述,谢谢各位啦!!有两题如下
发布网友
发布时间:2022-05-13 08:27
我来回答
共1个回答
热心网友
时间:2024-02-22 10:25
#include <stdio.h>
typedef struct _SQList
{
int data[200];
int len;
}SQList;
int InitSQList(SQList *s, int *a, int len)
{
int i;
for(i=0; i<len; i++)
s->data[i] = a[i];
s->len = len;
return 1;
}
int InsertSQList(SQList *s, int i, int data)
{
int j;
for (j=s->len-1; j>=i-1; j--)
{
s->data[j+1] = s->data[j];
}
s->data[j+1] = data;
(s->len)++;
return 1;
}
int PrintSQList(SQList s)
{
int i;
printf("\n");
for (i=0; i<s.len; i++)
{
printf("%5d", s.data[i]);
}
printf("\n");
return 1;
}
int main()
{
int data[]={14, 21, 7, 45, 28, 3, 56, 32};
SQList sqlist;
InitSQList(&sqlist, data, 8);
PrintSQList(sqlist);
InsertSQList(&sqlist, 3, 99);
PrintSQList(sqlist);
return 0;
}
你试试吧,我调试过了已经