顺序表的应用Word格式.docx
- 文档编号:19913339
- 上传时间:2023-01-12
- 格式:DOCX
- 页数:8
- 大小:76.46KB
顺序表的应用Word格式.docx
《顺序表的应用Word格式.docx》由会员分享,可在线阅读,更多相关《顺序表的应用Word格式.docx(8页珍藏版)》请在冰豆网上搜索。
源代码:
#include<
iostream.h>
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);
voidcha(SqList&
La,SqList&
Lb);
intLocateElem_Sq(SqListL,ElemTypee,Status(*compare)(ElemType,ElemType));
//基本操作的算法实现
L)
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!
L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
returnOK;
}
L,inti,ElemTypee)
ElemType*newbase,*p,*q;
if(i<
1||i>
L.length+1)
returnERROR;
if(L.length>
=L.listsize)
{
newbase=(ElemType*)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType));
if(!
newbase)exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
q=&
(L.elem[i-1]);
for(p=&
(L.elem[L.length-1]);
p>
=q;
--p)
*(p+1)=*p;
*q=e;
++L.length;
StatusListDelete_Sq(SqList&
L,inti,ElemType&
e)
ElemType*p,*q;
if((i<
1)||(i>
L.length))
p=&
e=*p;
q=L.elem+L.length-1;
for(++p;
p<
++p)
*(p-1)=*p;
--L.length;
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.length&
&
!
(*compare)(*p++,e))++i;
=L.length)returni;
elsereturn0;
voidmain()
intm,n,i;
ElemTypee;
SqListL1,L2;
InitList_Sq(L1);
InitList_Sq(L2);
cout<
<
"
请输入L1表的长度"
;
cin>
>
m;
请输入L2表的长度"
n;
请输入"
m<
个元素到L1表中"
endl;
=m;
cin>
e;
ListInsert_Sq(L1,i,e);
n<
个元素到L2表中"
=n;
ListInsert_Sq(L2,i,e);
L1表的内容"
=ListLength_Sq(L1);
GetElem_Sq(L1,i,e);
cout<
e<
\t"
L2表的内容"
=ListLength_Sq(L2);
GetElem_Sq(L2,i,e);
输出L1和L2的合并后"
Unoin(L1,L2);
输出L1和L2的差后"
cha(L1,L2);
运行结果:
1
2
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 顺序 应用