#include <STDIO.H>
#include <IOSTREAM>
#define TRUE 1;
#define FALSE 0;
#define OK 1;
#define ERROR 0;
#define INFEASIBLE -1;
#define OVERFLOW -2;
#define LIST_INIT_SIZE 100
#define LISTCREMENT 10
typedef int ElemType;
typedef int Status;
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList_Sq(SqList &L){
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
//if(!L.elem) exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
Status ListInsert_Sq(SqList &L,int i,ElemType e){
ElemType* newbase;
ElemType* p;
ElemType* q;
if(i<1||i>L.length+1)return ERROR;
if(L.length>L.listsize){
newbase=(ElemType*)realloc(L.elem,(L.listsize+LISTCREMENT)*sizeof(ElemType));
L.elem=newbase;
L.listsize+=LISTCREMENT;
}
q=&(L.elem[i-1]);
for (p=&(L.elem[L.length-1]);p>=q; --p) *(p+1) = *p;
*q=e;
++L.length;
return OK;
}
int main(){
return 0;
}
上面代码里,有ElemType *elem;其中ElemType 是一个int ,为什么我看见书本上写成elemt[1],elemt[2],可是elem明明就是一个int*数据类型,不是一个数组,为什么可以用下标
|
|