69,371
社区成员
发帖
与我相关
我的任务
分享
int insert( ABList *L , AddressBook *student , int i)// *****************插入新信息******
{
if(L->length==MAXSIZE)
{
printf("overflow");
return 0;
}
else if ( ( i<0) || (i>L->length))
{
printf("error,please input the right 'i'");
return 0;
}
else
{
int j;
for ( j=L->length-1 ; j>=i ; j--)
{
L->stu[j+1].ID=L->stu[j].ID;
strcpy(L->stu[j+1].name,L->stu[j].name);
strcpy(L->stu[j+1].sex,L->stu[j].sex);
strcpy(L->stu[j+1].phone,L->stu[j].phone);
strcpy(L->stu[j+1].addr,L->stu[j].addr);
}
L->stu[i].ID=student->ID;
strcpy(L->stu[i].name,student->name);
strcpy(L->stu[i].sex,student->sex);
strcpy(L->stu[i].phone,student->phone);
strcpy(L->stu[i].addr,student->addr);
L->length=L->length+1;
return 1;
}
}
struct People
{
char name[20];
int age;
...
};
List L;
PeoPle *p = new PeoPle;
memcpy(p->name, "lijun", 5);
p->age = 20;
L.insert(p);//将该信息插入链表里面