#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define TURE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
#define LIST_INIT_SIZE 100 //初始容量
#define LISTINCREMENT 10 //空间增量
typedef struct{
ElemType *elem; //存储空间基址
int length; //表长,元素个数
int listsize; //表容量,空间大小
}SqList;
Status InitList_Sq(SqList &L) {
//构造一个空的线性表 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;
}
void Input_Sq(SqList &L) {
//输入数据
int n,i,x;
printf("Please input the SqList's length:");
scanf("%d",&n);
L.length=n;
for(i=0;i<n;i++ )
{
printf("Please input %dth elem:",i);
scanf("%d",&x);
L.elem[i]=x;
}
评论1
最新资源