数据结构第02讲_线性表类型定义与顺序表_C.pptVIP

  • 49
  • 0
  • 约7.91千字
  • 约 40页
  • 2016-08-23 发布于重庆
  • 举报

数据结构第02讲_线性表类型定义与顺序表_C.ppt

数据结构第02讲_线性表类型定义与顺序表_C

* * status listinsert (SqList L,int i,ElemtType e) { if (i1 || iL.len+1) return ERROR; // i值不合法 if (L.len = = L.lsize) { // 当前存储空间已满,增加分配 newbase = (Elemtype * ) realloc(L.elem, (L.lsize + LISTINCREMENT) * (sizeof(ElemType)); if (!newbase) exit(overflow); // 存储分配失败 L.elem = newbase; // 新基址 lsize += LISTINCREMENT; } // 增加存储容量 q = (L.elem[i-1]); // q为插入位置 for (p = (L.elem[L.len-1]);p=q;--p) *(P+1) = * P; // 元素后移 *q = e; ++L.len; // 插入e,表长增1 return OK; } //listinsert 注意:C语言中数组的下标从“0”开始,因此,若L是SqLis

文档评论(0)

1亿VIP精品文档

相关文档