数 据 结 构 作 业 2013 作 业 1
线性表 编 程 作 业 : 1. 将 顺 序 表 逆 置 , 要 求 用 最 少 的 附 加 空 间
参考答案 #include #include #include #define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE -1 #define OVERFLOW -2 typedef int Status; typedef int ElemType; typedef struct { ElemType *elem; int length; int listsize; }SqList; //创建空顺序表 Status InitList_Sq( SqList &L ) { L
elem = (ElemType*) malloc (LIST_INIT_SIZE*sizeof(ElemType)); if (
elem) exit(OVERFLOW); L
length = 0; 数 据 结 构 作 业 2013 L
listsize = LIST_INIT_SIZE; return OK; } //顺 序 表 在 第 i 个元素之前插入 e Status sxbcr(SqList &L, int i, ElemType e) { ElemType *p,*q; if((iL
length+1)) return (ERROR); else { q=&(L
elem[i-1]); for(p=&(L
elem[L
length-1]);p>=q;--p) *(p+1)=*p; *q=e; ++L
length; return (