#include<stdio.h>
#define Maxsize 100
typedef struct {
int adress;
int score;
char sex;
}Datatype;
Datatype NIL;
typedef struct{
Datatype Data[Maxsize];
int size;
}list;
int Length(list l)
{ return l.size;}
Datatype Get(list l,int i)
{ if(i>0&&i<=Length(l)) {return l.Data[i-1];}
else {return NIL ;}
}
int Insert(list *l,int i,Datatype x)
{int j;
if(i<0||i>Length(*l))
{printf("i插入的位置不合法!\n");
return 0;}
for(j=(l->size)-1;j>=i-1;j--)
{ l->Data[j+1]=l->Data[j];}
l->Data[i-1]=x;
(l->size)++;
printf("插入成功\n");
return 1;加粗样式
}
void main()
{list l={100,88,'M',101,99,'W',102,70,'M',103,89,'W',104,100,'M',105,96,'M'};
l.size=5;
Datatype x={106,100,'M'};
int i=2;
Insert(&l,i,x);
printf("adress=%d\nscore=%d\nsex=%c\n",l.Data[1].adress,l.Data[1].score,l.Data[1].sex);
}
线性顺序表的插入
最新推荐文章于 2022-05-09 22:10:43 发布