顺序表的应用Word文档下载推荐.docx
- 文档编号:14593938
- 上传时间:2022-10-23
- 格式:DOCX
- 页数:7
- 大小:15.55KB
顺序表的应用Word文档下载推荐.docx
《顺序表的应用Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《顺序表的应用Word文档下载推荐.docx(7页珍藏版)》请在冰豆网上搜索。
#include<
iostream.h>
#include<
stdlib.h>
#defineOK1
#defineTRUE1
#defineFALSE0#defineERROR0
#defineOVERFLOW-2
#defineLIST_INIT_SIZE100
#defineLISTINCREMENT10
typedefintStatus;
typedefintElemType;
typedefstruct//存储表示
{
ElemType*elem;
intlength;
intlistsize;
}SqList;
//基本操作的函数声明
StatusInitList_Sq(SqList&
L);
StatusListInsert_Sq(SqList&
L,inti,ElemTypee);
Statusequal(ElemTypea,ElemTypeb);
StatusGetElem_Sq(SqListL,inti,ElemType&
e);
intListLength_Sq(SqListL);
voidUnoin(SqList&
La,SqListLb);
L,ElemType
voidcha(SqList&
La,SqList&
Lb);
intLocateElem_Sq(SqList
e,Status(*compare)(ElemType,ElemType));
//基本操作的算法实现
StatusInitList_Sq(SqList&
L)
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!
L.elem)exit(OVERFLOW);
L.length=O;
L」istsize二LIST_INIT_SIZE;
returnOK;
}
L,inti,ElemTypee)
ElemType*newbase,*p,*q;
if(i<
1||i>
L.length+1)
returnERROR;
if(L.length>
=L」istsize)
newbase=(ElemType
*)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType));
newbase)exit(OVERFLOW);
L.elem=newbase;
L」istsize+二LISTINCREMENT;
q二&
(L.elem[i-1]);
for(p二&
(L.elem[L」ength-1]);
p>
=q;
--p)
*(p+1)=*p;
*q=e;
++L」ength;
StatusListDelete_Sq(SqList&
L,inti,ElemType&
e)
ElemType*p,*q;
if((i<
1)||(i>
L.length))
p二&
e=*p;
q=L.elem+L」ength-1;
for(++p;
p<
++p)
*(p-1)=*p;
--L」ength;
Lb)
intla_len,lb_len,i,e;
la_len=ListLength_Sq(La);
lb_len=ListLength_Sq(Lb);
for(i=1;
i<
=lb_len;
i++)
GetElem_Sq(Lb,i,e);
if(LocateElem_Sq(La,e,equal))
ListDelete_Sq(La,LocateElem_Sq(La,e,equal),e);
Statusequal(ElemTypea,ElemTypeb)
if(a==b)
returnTRUE;
elsereturnFALSE;
L.length)
e=*(L.elem+i-1);
intListLength_Sq(SqListL)
returnL.length;
La,SqListLb)
LocateElem_Sq(La,e,equal))
ListInsert_Sq(La,++la_len,e);
intLocateElem_Sq(SqListL,ElemTypee,Status(*compare)(ElemType,ElemType))
inti=1;
ElemType*p;
p=L.elem;
while(i<
二L」ength&
&
!
(*compare)(*p++,e))++i;
二L」ength)returni;
elsereturn0;
voidmain()
intm,n,i;
ElemTypee;
SqListL1,L2;
InitList_Sq(L1);
InitList_Sq(L2);
coutvv"
请输入L1表的长度"
cin>
>
m;
请输入L2表的长度"
n;
请输入"
v<
m<
v"
个元素到L1表中"
<
endl;
=m;
>
e;
ListInsert_Sq(L1,i,e);
vvnvv"
个元素到L2表中"
二n;
ListInsert_Sq(L2,i,e);
cout<
"
L1表的内容"
=ListLength_Sq(L1);
i++){
GetElem_Sq(L1,i,e);
cout<
e<
\t"
;
cout«
endl;
L2表的内容"
for(i=1;
=ListLength_Sq(L2);
GetElem_Sq(L2,i,e);
输出L1和L2的合并后"
Unoin(L1,L2);
二ListLength_Sq(L1);
输出L1和L2的差后"
cha(L1,L2);
运行结果:
1
2
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 顺序 应用
![提示](https://static.bdocx.com/images/bang_tan.gif)