请各位高手看看有两个问题。。帮忙改一下
// List.cpp : 定义控制台应用程序的入口点。//
#include "stdio.h"
#include "string.h"
#define DataType int
#define MAXSIZE 100 //初始量
struct SList{
char name[20];
char grade[20];
};
struct sum{
struct SList record[MAXSIZE];
int len;
};
struct sum InitSList()
{ //初始化线性表
struct sum L;
L.len=-1;
return L;
}
int InsertSList(struct sum &L,int i,char* x,char* y)
{ //在第i个元素之前插入一个新结点
int j;
if (L.len==MAXSIZE-1)
return (-1);
if (i<1||i>L.len+2)
return (0);
for (j=L.len;j>=i-1;j--)
L.record[j+1]=L.record[j];
// L.record[j+1].grade=L.record[j].grade;
L.record[i-1].name= *x;
L.record[i-1].grade= *y;
L.len++;
return 1;
}
int DeleteSList(struct sum &L,int i)
{ //删除第i个元素
int j;
if (L.len==-1)
return (-1);
if (i<1||i>L.len+2)
return (0);
for (j=i;j<=L.len;j++)
L.record[j-1]=L.record[j];
L.len--;
return 1;
}
void printSList(struct sum &L)
{
printf("The elements in the SList are:\n");
for(int i=0;i<=L.len;i++)
printf("%s %s",L.record[i].name,L.record[i].grade);
printf("\n");
}
int main()
{
struct sum L=InitSList();
printf("please input the name and grade of math into the L:\n");
char tem[20], q[20];
int p;
scanf("%s %s",tem,q);
while(strcmp(tem,"-1")==0)
{
InsertSList(L,L.len+2,tem,q);
scanf("%s %s",tem,q);
}
printSList(L);
printf("please input the name and grade and its position you want to insert into the L:\n");
scanf("%s %s %d",tem,q,&p);
InsertSList(L,p,tem,q);
printSList(L);
printf("please input the element's position you want to delete from the L:\n");
scanf("%d",&p);
DeleteSList(L,p);
printSList(L);
return 0;
}