#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
typedef int Status;
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)
{
if(i<1||i>=L.length+1)return ERROR;
if(L.length>=L.listsize)
{
newbase = (ElemType *)realloc(L.elem,
(L.listsize+LISTINCREMENT) *sizeof(ElemType));
if(!newbase)exit(OBERFLOW);
L.elem = newbase;
L.listsize += LISTINCREMENT;
}
for (k=L.length;k>=i;k--)
L.elem[k-1]=L.elem[k-2];
L.elem[i-1]=e;
++L.length;
return OK;
}
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
typedef int Status;
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)
{
if(i<1||i>=L.length+1)return ERROR;
if(L.length>=L.listsize)
{
newbase = (ElemType *)realloc(L.elem,
(L.listsize+LISTINCREMENT) *sizeof(ElemType));
if(!newbase)exit(OBERFLOW);
L.elem = newbase;
L.listsize += LISTINCREMENT;
}
for (k=L.length;k>=i;k--)
L.elem[k-1]=L.elem[k-2];
L.elem[i-1]=e;
++L.length;
return OK;
}