顺序栈(SequenceStack) SqStack。cpp:authorhuihutEmail:huihutoutlook。comversion创建时间:2016年9月9日说明:本程序实现了一个顺序栈。功能:有初始化、销毁、判断空、清空、入栈、出栈、取元素的操作。includestdio。hincludestdlib。hincludemalloc。h5个常量定义defineTRUE1defineFALSE0defineOK1defineERROR0defineOVERFLOW1测试程序长度定义defineLONGTH5类型定义typedefintStypedefintElemT顺序栈的类型typedefstruct{ElemT}SqS初始化顺序栈StatusInitStackSq(SqSrackS,intsize,intinc){S。elem(ElemType)malloc(sizesizeof(ElemType));if(NULLS。elem)returnOVERFLOW;S。top0;S。S。returnOK;}销毁顺序栈StatusDestroyStackSq(SqSrackS){free(S。elem);S。elemNULL;returnOK;}判断S是否空,若空则返回TRUE,否则返回FALSEStatusStackEmptySq(SqSrackS){if(0S。top)returnTRUE;returnFALSE;}清空栈SvoidClearStackSq(SqSrackS){if(0S。top)S。size0;S。top0;}元素e压入栈SStatusPushSq(SqSrackS,ElemTypee){ElemTif(S。topS。size){newbase(ElemType)realloc(S。elem,(S。sizeS。increment)sizeof(ElemType));if(NULLnewbase)returnOVERFLOW;S。S。sizeS。}S。elem〔S。top〕e;returnOK;}取栈S的栈顶元素,并用e返回StatusGetTopSq(SqSrackS,ElemTypee){if(0S。top)returnERROR;eS。elem〔S。top1〕;}栈S的栈顶元素出栈,并用e返回StatusPopSq(SqSrackS,ElemTypee){if(0S。top)returnERROR;eS。elem〔S。top1〕;S。}intmain(){定义栈SSqSrackS;定义测量值intsize,increment,i;初始化测试值sizeLONGTH;incrementLONGTH;ElemTypee,eArray〔LONGTH〕{1,2,3,4,5};显示测试值printf(【顺序栈】);printf(栈S的size为:d栈S的increment为:d,size,increment);printf(待测试元素为:);for(i0;iLONGTH;i){printf(d,eArray〔i〕);}printf();初始化顺序栈if(!InitStackSq(S,size,increment)){printf(初始化顺序栈失败);exit(0);}printf(已初始化顺序栈);入栈for(i0;iS。i){if(!PushSq(S,eArray〔i〕)){printf(d入栈失败,eArray〔i〕);exit(0);}}printf(已入栈);判断非空if(StackEmptySq(S))printf(S栈为空);elseprintf(S栈非空);取栈S的栈顶元素printf(栈S的栈顶元素为:);printf(d,GetTopSq(S,e));栈S元素出栈printf(栈S元素出栈为:);for(i0,e0;iS。i){printf(d,PopSq(S,e));}printf();清空栈SClearStackSq(S);printf(已清空栈S);getchar();return0;} 顺序栈数据结构和图片typedefstruct{ElemT}SqS 队列(SequenceQueue) 队列数据结构typedefstruct{ElemTintmaxS}SqQ 非循环队列 非循环队列图片 SqQueue。rear 循环队列 循环队列图片 SqQueue。rear(SqQueue。rear1)SqQueue。maxSize顺序表(SequenceList) SqList。cpp:authorhuihutEmail:huihutoutlook。comversion创建时间:2016年9月9日说明:本程序实现了一个顺序表。includestdio。hincludestdlib。hincludemalloc。h5个常量定义defineTRUE1defineFALSE0defineOK1defineERROR0defineOVERFLOW1测试程序长度定义defineLONGTH5类型定义typedefintStypedefintElemT顺序栈的类型typedefstruct{ElemT}SqL初始化顺序表LStatusInitListSq(SqListL,intsize,intinc){L。elem(ElemType)malloc(sizesizeof(ElemType));if(NULLL。elem)returnOVERFLOW;L。length0;L。L。returnOK;}销毁顺序表LStatusDestroyListSq(SqListL){free(L。elem);L。elemNULL;returnOK;}将顺序表L清空StatusClearListSq(SqListL){if(0!L。length)L。length0;returnOK;}若顺序表L为空表,则返回TRUE,否则FALSEStatusListEmptySq(SqListL){if(0L。length)returnTRUE;returnFALSE;}返回顺序表L中元素个数intListLengthSq(SqListL){returnL。}用e返回顺序表L中第i个元素的值StatusGetElemSq(SqListL,inti,ElemTypee){eL。elem〔i〕;returnOK;}在顺序表L顺序查找元素e,成功时返回该元素在表中第一次出现的位置,否则返回1intSearchSq(SqListL,ElemTypee){inti0;while(iL。lengthL。elem〔i〕!e)i;if(iL。length)elsereturn1;}遍历调用Statusvisit(ElemTypee){printf(d,e);returnOK;}遍历顺序表L,依次对每个元素调用函数visit()StatusListTraverseSq(SqListL,Status(visit)(ElemTypee)){if(0L。length)returnERROR;for(inti0;iL。i){visit(L。elem〔i〕);}returnOK;}将顺序表L中第i个元素赋值为eStatusPutElemSq(SqListL,inti,ElemTypee){if(iL。length)returnERROR;eL。elem〔i〕;returnOK;}在顺序表L表尾添加元素eStatusAppendSq(SqListL,ElemTypee){if(L。lengthL。size)returnERROR;L。elem〔L。length〕e;L。returnOK;}删除顺序表L的表尾元素,并用参数e返回其值StatusDeleteLastSq(SqListL,ElemTypee){if(0L。length)returnERROR;eL。elem〔L。length1〕;L。returnOK;}intmain(){定义表LSqListL;定义测量值intsize,increment,i;初始化测试值sizeLONGTH;incrementLONGTH;ElemTypee,eArray〔LONGTH〕{1,2,3,4,5};显示测试值printf(【顺序栈】);printf(表L的size为:d表L的increment为:d,size,increment);printf(待测试元素为:);for(i0;iLONGTH;i){printf(d,eArray〔i〕);}printf();初始化顺序表if(!InitListSq(L,size,increment)){printf(初始化顺序表失败);exit(0);}printf(已初始化顺序表);判空if(TRUEListEmptySq(L))printf(此表为空表);elseprintf(此表不是空表);入表printf(将待测元素入表:);for(i0;iLONGTH;i){if(ERRORAppendSq(L,eArray〔i〕))printf(入表失败);;}printf(入表成功);遍历顺序表Lprintf(此时表内元素为:);ListTraverseSq(L,visit);出表printf(将表尾元素入表到e:);if(ERRORDeleteLastSq(L,e))printf(出表失败);printf(出表成功出表元素为d,e);遍历顺序表Lprintf(此时表内元素为:);ListTraverseSq(L,visit);销毁顺序表printf(销毁顺序表);if(OKDestroyListSq(L))printf(销毁成功);elseprintf(销毁失败);getchar();return0;} 顺序表数据结构和图片typedefstruct{ElemT}SqL 今天的分享就到这里了,大家要好好学C哟 写在最后:对于准备学习CC编程的小伙伴,如果你想更好的提升你的编程核心能力(内功)不妨从现在开始! 编程学习视频分享: 整理分享(多年学习的源码、项目实战视频、项目笔记,基础入门教程) 欢迎转行和学习编程的伙伴,利用更多的资料学习成长比自己琢磨更快哦! 对于CC感兴趣可以关注小编在后台私信我:【编程交流】一起来学习哦!可以领取一些CC的项目学习视频资料哦!已经设置好了关键词自动回复,自动领取就好了!