顺序表的应用Word格式.docx

上传人:b****6 文档编号:19913339 上传时间:2023-01-12 格式:DOCX 页数:8 大小:76.46KB
下载 相关 举报
顺序表的应用Word格式.docx_第1页
第1页 / 共8页
顺序表的应用Word格式.docx_第2页
第2页 / 共8页
顺序表的应用Word格式.docx_第3页
第3页 / 共8页
顺序表的应用Word格式.docx_第4页
第4页 / 共8页
顺序表的应用Word格式.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

顺序表的应用Word格式.docx

《顺序表的应用Word格式.docx》由会员分享,可在线阅读,更多相关《顺序表的应用Word格式.docx(8页珍藏版)》请在冰豆网上搜索。

顺序表的应用Word格式.docx

源代码:

#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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 工作总结汇报

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1