利用线性表的插入,实现数组插入
本人初学数据结构,就遇到了难题。这个代码有一个警告,请帮我一下,怎样才运行出来。谢谢#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#include<stdio.h>
#include<malloc.h>
typedef struct
{
char *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList &L);
int ListInsert_Sq(SqList &L,int i,char e);
void main()
{
int m;
char c;
SqList *aa=new SqList[7];
InitList_Sq(aa[7]);
printf("输入被插入数组:\n");
for(int s=0;s<7;s++)
scanf("%c",&aa[s]);
printf("输入待插入字符:\n");
scanf("%c",c);
ListInsert_Sq(aa[7],m=4,c);
for(int j=0;j<8;j++)
printf("%c",aa[j]);
}
int InitList_Sq(SqList &L){
L.elem=(char *)malloc(LIST_INIT_SIZE *sizeof(char));
if(!L.elem)return -2;
L.length=0;
L.listsize=LIST_INIT_SIZE;
return 1;
}
int ListInsert_Sq(SqList &L,int i,char e)
{
if(i<i || i>L.length+1)return 0;
if(L.length>=L.listsize){
char *newbase=(char *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(char));
if(!newbase)return -2;
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
char *q=&(L.elem[i-1]);
char *p;
for(p=&(L.elem[L.length-1]);p>=q;--p)*(p+1)=*p;
*q=e;
++(L.length);
return 1;
}