1、#include#define MaxLen 50typedef int elemtype;typedef elemtype sqlistMaxLen;int create(sqlist A)int i,n;cout n;for (i=0;iAi;return n;#include using namespace std;#define LIST_INIT_SIZE 100/线性表存储空间的初始分配量 #define LISTINCREMENT 10/线性表存储空间的分配增量typedef int ElemType;typedef int Status;#define OK 1#define
2、OVERFLOW -1#define ERROR -2typedef struct/用户自定义结构体 SqListElemType *elem;/指针指向存储空间基址int length;int listsize;SqList;/线性表初始化Status Initlist_Sq(SqList if(!L.elem) exit(OVERFLOW);L.length =0;/空表长度为 0L.listsize=LIST_INIT_SIZE; /初始存储容量return OK;/Put 操作Status Put(SqList L.length =L.length +n;return OK; /Out
3、 操作Status Out(SqList iL.length+1) return ERROR;/i 的值不合法if(L.length =L.listsize) /存储空间已满,增加分配newbase=(ElemType*)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType);if(!newbase)exit(OVERFLOW);/重新分配失败L.elem=newbase;L.listsize+=LISTINCREMENT;/增加分配容量q=/q 为插入地址for(p=p=q;-p) *(p+1)=*p;/插入元素后移*q=e;+L.length;return OK;/Delete 操作Status ListDelete_Sq(SqList p=e=*p;q=L.elem+L.length-1;for (+p;pn;Put(La,n);coutik;ListInsert_Sq(La,i,k);coutj;ListDelete_Sq(La,j,e);coutf;cout“数据 f 在线性表中的位置 :“LocateElem_Sq(La,f)endl;return 0;