线性表的动态表示和实现Word格式.docx

上传人:b****5 文档编号:15838872 上传时间:2022-11-16 格式:DOCX 页数:16 大小:48.47KB
下载 相关 举报
线性表的动态表示和实现Word格式.docx_第1页
第1页 / 共16页
线性表的动态表示和实现Word格式.docx_第2页
第2页 / 共16页
线性表的动态表示和实现Word格式.docx_第3页
第3页 / 共16页
线性表的动态表示和实现Word格式.docx_第4页
第4页 / 共16页
线性表的动态表示和实现Word格式.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

线性表的动态表示和实现Word格式.docx

《线性表的动态表示和实现Word格式.docx》由会员分享,可在线阅读,更多相关《线性表的动态表示和实现Word格式.docx(16页珍藏版)》请在冰豆网上搜索。

线性表的动态表示和实现Word格式.docx

intlength;

intlistsize;

public:

//初始化顺序表

voidinit(List*L);

//删除顺序表

voidDestroyList(List&

L);

//将顺序表置为空表

voidClearList();

//判断顺序表是否为空

boolListEmpty();

//判断顺序表是否为满

boolListFull();

//决定返回表中元素pre_e的前驱

ElemTypePriorElem(ElemTypecur_e,ElemType&

pre_e);

//决定返回表中元素next_e的后继

ElemTypeNextElem(ElemTypecur_e,ElemType&

next_e);

//从线性表中删除表头,表尾,或等于给定值的元素

boolListDelete(int,ElemType&

e);

//遍历顺序表

voidListTraverse();

//返回顺序表的长度

intListLength();

//获取顺序表中的第i个元素

voidGetElem(int,ElemType*);

//判断顺序表两元素是否相等

boolEqualList(ElemType*,ElemType*);

//判断顺序表两元素是否不等

boolLess_EqualList(ElemType*,ElemType*);

//顺序表的查找算法

boolLocateElem(ElemType,int);

//更新线性表中的给定元素

boolUpdateList(ElemType&

e,ElemType);

//顺序表的合并算法

voidMergeList(List*,List*);

//顺序表的插入算法

boolListInsert(int,ElemType&

);

//顺序表的联合算法

voidUnionList(List*,List*);

//对线性表按升序或降序输出

voidprintlist(int);

};

Linelist2.cpp

#include"

linelist2.h"

#include<

iomanip>

iostream>

string>

malloc.h>

usingnamespacestd;

voidList:

:

init(List*L)

L->

elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));

if(!

L->

elem)

exit(OVERFLOW);

length=0;

listsize=LIST_INIT_SIZE;

}

DestroyList(List&

L)

free(&

ClearList()

length=0;

boolList:

ListEmpty()

if(length==0)

returntrue;

else

returnfalse;

ListFull()

if(length==listsize)

ElemTypeList:

PriorElem(ElemTypecur_e,ElemType&

pre_e)

for(inti=0;

i<

length;

i++)

if((i!

=0)&

&

strcmp(cur_e.name,elem[i].name)==0)

{

pre_e=elem[i-1];

returnpre_e;

}

returncur_e;

NextElem(ElemTypecur_e,ElemType&

next_e)

=length-1)&

next_e=elem[i+1];

returnnext_e;

ListDelete(intmark,ElemType&

e)//mark>

0删除表头mark<

0删除表尾mark=0删除e

inti,j;

if(ListEmpty())

if(mark>

0)

{

e=elem[0];

for(i=1;

elem[i-1]=elem[i];

}

else

if(mark<

e=elem[length-1];

else{

for(i=0;

if(strcmp(elem[i].name,e.name))

break;

if(i>

=length)

returnfalse;

else

e=elem[i];

for(j=i+1;

j<

j++)

elem[i-1]=elem[i];

length--;

returntrue;

ListTraverse()

cout<

<

setw(8)<

elem[i].name;

cout<

setw(10)<

elem[i].stuno;

setw(9)<

elem[i].age;

elem[i].score<

endl;

intList:

ListLength()

returnlength;

GetElem(inti,ElemType*e)

while(i<

1||i>

length)

"

请输入1-"

length<

之间的数:

;

cin>

>

i;

*e=elem[i-1];

EqualList(ElemType*e1,ElemType*e2)

if(strcmp((*e1).name,(*e2).name))

if((*e1).age!

=(*e2).age)

if(strcmp((*e1).stuno,(*e2).stuno))

if((*e1).score!

=(*e2).score)

Less_EqualList(ElemType*e1,ElemType*e2)

if(strcmp(e1->

name,e2->

name)==0)

LocateElem(ElemTypee,inttype)

inti;

switch(type){

caseEQUAL:

for(i=0;

if(EqualList(&

elem[i],&

e))

returntrue;

break;

default:

break;

returnfalse;

UpdateList(ElemType&

e,ElemTypee1)

if(strcmp(elem[i].name,e.name)==0)

elem[i]=e1;

returntrue;

MergeList(List*La,List*Lb)

intLa_len,Lb_len;

La_len=La->

ListLength();

Lb_len=Lb->

La_len;

elem[i]=La->

elem[i];

for(intj=0;

Lb_len;

elem[j+i]=Lb->

elem[j];

length=La_len+Lb_len;

//MaxSize=La->

MaxSize+Lb->

MaxSize;

ListInsert(inti,ElemType&

e)

ElemType*p,*q,*newbase;

if(i<

length+1)

if(length>

=listsize)

newbase=(ElemType*)realloc(elem,(listsize+LISTINCREMENT)*sizeof(ElemType));

if(!

newbase)

exit(OVERFLOW);

elem=newbase;

listsize=LISTINCREMENT+listsize;

q=&

elem[i-1];

p=&

elem[length-1];

for(p;

p>

=q

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

当前位置:首页 > 高中教育 > 语文

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

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