数据结构顺序操作

上传人:kms****20 文档编号:40551054 上传时间:2018-05-26 格式:DOC 页数:3 大小:18KB
返回 下载 相关 举报
数据结构顺序操作_第1页
第1页 / 共3页
数据结构顺序操作_第2页
第2页 / 共3页
数据结构顺序操作_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《数据结构顺序操作》由会员分享,可在线阅读,更多相关《数据结构顺序操作(3页珍藏版)》请在金锄头文库上搜索。

1、#include #include#define MaxSize 50 typedef int ElemType ; typedef struct ElemType elemMaxSize;int length; SqList; void IntList(SqList *L ) L=(SqList *)malloc(sizeof(SqList);L-length=0; void DestroyList(SqList *L) free(L); void clearlist(SqList *L) L-length=0; int ListEmpty(SqList *L) return(L-lengt

2、h=0) ; int ListLength(SqList *L) return(L-length); int GetElem(SqList *L,int i,ElemType e) if(iL-length)return 0;e=L-elemi-1;return 1; int LocateElem(SqList *L,ElemType e) int i=0;while(ilengthif(i=L-length)return 0;elsereturn i+1; int ListInsert(SqList *L ,int i ,ElemType e) int j;if(iL-length+1)re

3、turn 0;i-;for(j=L-length;ji;j-)L-elemj=L-elemj-1;L-elemi=e;L-length+; int ListDelete(SqList *L,int i ,ElemType e) int j;if(iL-length)return 0;i-;e=L-elemi;for(j=i;jlength-1;j+)L-elemj=L-elemj+1;L-length-;return 1; void main() SqList *L;int a,b,c,d,e,f,i;printf(“(1)初始化顺序表 Ln“);IntList(L);L=( SqList*)

4、malloc(MaxSize*sizeof( SqList);printf (“(2)依次采用尾插入法 插入 a,b,c,d,e 元素n“);scanf(“%d%d%d%d%d“,ListInsert(L,1,a);ListInsert(L,2,b);ListInsert(L,3,c);ListInsert(L,4,d);ListInsert(L,5,e);printf(“(3)输出顺序表 L:“);for(i=0;ielemi);printf(“(4)顺序表 L 长度=%dn“,ListLength(L);printf(“(5)顺序表 L 为%sn“,(ListEmpty(L)?“空“:“非

5、空“);GetElem(L,3,e);printf(“(6)顺序表 L 的第 3 个元素=%dn“,e);printf(“(7)元素 a 的位置=%dn“,LocateElem(L,a);printf(“(8)在第 4 个元素位置上插入 f 元素n“);scanf(“%d“,ListInsert(L,4,f);printf(“(9)输出顺序表 L:n“);for(i=0;ielemi);printf(“(10)删除 L 的第 3 个元素:n“);ListDelete(L,3,e);printf(“(11)输出顺序表 L:n“);for(i=0;ielemi);printf(“(12)释放顺序表 L:n“);DestroyList(L);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号