顺序表的问题,书上的伪代码调不出来求大神指导
程序代码:
#include <stdio.h> #include <stdlib.h> #define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define TURE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE -1 #define OVERFLOW -2 typedef struct { int *elem; int length; int listsize; }SqList; void InitList(SqList L) { L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int)); if(!L.elem)exit(OVERFLOW); L.length=0; L.listsize=LIST_INIT_SIZE; int i; for(i=0;i<10;i++) { int el[20]; scanf("%d",&el[i]); L.elem[i]->date=el[i]; L.length++; } } void ListInsert(&L,int i,int b){ scanf("%d%d",&i,&b); if(i<1||i>L.length+1)return ERROR; if(L.length>=L.listsize){ int newbase; newbase=(int *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(int)); if(!newbase)exit(0); L.elem=newbase; L.listsize+=LISTINCREMENT;} int *p,*q; q=&(L.elem[i-1]); for(p=&L.elem[L.length-1];p>=q;--p) { *(p+1)=*p; *q=b; ++L.length; return OK; } } int main() { int a; printf("输入十个整数\n"); InitList(SqList L); printf("输入要插入的位置和元素\n"); ListInsert(SqList L,int i,int a); getch(); }