华农数据结构上机实验答案教学提纲Word文档下载推荐.docx

上传人:b****2 文档编号:14890488 上传时间:2022-10-25 格式:DOCX 页数:119 大小:38.02KB
下载 相关 举报
华农数据结构上机实验答案教学提纲Word文档下载推荐.docx_第1页
第1页 / 共119页
华农数据结构上机实验答案教学提纲Word文档下载推荐.docx_第2页
第2页 / 共119页
华农数据结构上机实验答案教学提纲Word文档下载推荐.docx_第3页
第3页 / 共119页
华农数据结构上机实验答案教学提纲Word文档下载推荐.docx_第4页
第4页 / 共119页
华农数据结构上机实验答案教学提纲Word文档下载推荐.docx_第5页
第5页 / 共119页
点击查看更多>>
下载资源
资源描述

华农数据结构上机实验答案教学提纲Word文档下载推荐.docx

《华农数据结构上机实验答案教学提纲Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《华农数据结构上机实验答案教学提纲Word文档下载推荐.docx(119页珍藏版)》请在冰豆网上搜索。

华农数据结构上机实验答案教学提纲Word文档下载推荐.docx

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

L.length=0;

L.listsize=LIST_INIT_SIZE;

returnOK;

}

intLoad_Sq(SqList&

inti;

if(L.length==0)

printf("

TheListisempty!

"

);

else

{

TheListis:

for(i=0;

i<

L.length;

i++)

printf("

%d"

L.elem[i]);

}

printf("

\n"

intListInsert_Sq(SqList&

L,inti,inte)

if(i<

1||i>

L.length+1)

returnERROR;

ElemType*newbase,*q,*p;

if(L.length>

=L.listsize)

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

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;

intListDelete_Sq(SqList&

L,inti,int&

e)

ElemType*q,*p;

L.length)

p=&

e=*p;

q=L.elem+L.length-1;

for(++p;

p<

p++)

*(p-1)=*p;

L.length--;

intmain()

SqListT;

inta,i;

ElemTypee,x;

if(InitList_Sq(T))

ASequenceListHasCreated.\n"

while

(1)

1:

Insertelement\n2:

Deleteelement\n3:

Loadallelements\n0:

Exit\nPleasechoose:

scanf("

%d"

&

a);

switch(a)

{

case1:

scanf("

%d%d"

i,&

x);

if(!

ListInsert_Sq(T,i,x))

printf("

InsertError!

else

TheElement%disSuccessfullyInserted!

x);

break;

case2:

i);

ListDelete_Sq(T,i,e))

DeleteError!

else

TheElement%disSuccessfullyDeleted!

e);

case3:

Load_Sq(T);

case0:

return1;

}

1.2合并顺序表

for(i=0;

%d"

intListLength(SqListL)

returnL.length;

intGetElem(SqListL,inti,ElemType&

e=L.elem[i-1];

ElemType*p,*q,*newbase;

if(L.listsize<

=L.length)

p--)

L.length++;

voidMergeList(SqListLa,SqListLb,SqList&

Lc)

inti,j,k,La_len,Lb_len,ai,bj;

i=j=1;

k=0;

InitList_Sq(Lc);

La_len=ListLength(La);

Lb_len=ListLength(Lb);

while((i<

=La_len)&

&

(j<

=Lb_len))

GetElem(La,i,ai);

GetElem(Lb,j,bj);

if(ai<

=bj)

ListInsert_Sq(Lc,++k,ai);

i++;

else

ListInsert_Sq(Lc,++k,bj);

j++;

while(i<

=La_len)

GetElem(La,i++,ai);

ListInsert_Sq(Lc,++k,ai);

while(j<

=Lb_len)

GetElem(Lb,j++,bj);

ListInsert_Sq(Lc,++k,bj);

Load_Sq(Lc);

intan,bn,i,e;

SqListLa,Lb,Lc;

InitList_Sq(La);

an);

for(i=1;

=an;

e);

ListInsert_Sq(La,i,e);

ListA:

Load_Sq(La);

InitList_Sq(Lb);

bn);

ListInsert_Sq(Lb,i,e);

ListB:

Load_Sq(Lb);

ListC:

MergeList(La,Lb,Lc);

return0;

1.3顺序表逆置

#defineElemTypeint

if(!

L.elem)

NO1"

ThisListisempty!

ElemType*newbase,*p,*q;

if(!

newbase)

NO2"

returnERROR;

intswap(SqList&

L,intn)

inti,j,temp;

for(i=

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

当前位置:首页 > 高等教育 > 经济学

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

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