(第1版)数据结构实验指导(精选).docx

上传人:b****9 文档编号:158130 上传时间:2022-10-04 格式:DOCX 页数:14 大小:186.80KB
下载 相关 举报
(第1版)数据结构实验指导(精选).docx_第1页
第1页 / 共14页
(第1版)数据结构实验指导(精选).docx_第2页
第2页 / 共14页
(第1版)数据结构实验指导(精选).docx_第3页
第3页 / 共14页
(第1版)数据结构实验指导(精选).docx_第4页
第4页 / 共14页
(第1版)数据结构实验指导(精选).docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

(第1版)数据结构实验指导(精选).docx

《(第1版)数据结构实验指导(精选).docx》由会员分享,可在线阅读,更多相关《(第1版)数据结构实验指导(精选).docx(14页珍藏版)》请在冰豆网上搜索。

(第1版)数据结构实验指导(精选).docx

3Projects

3.1Project1:

PerformanceMeasurement

9

Givenalistofordered

Nintegers,numberedfrom0to

N–1,checkingtoseethatNisnot

inthislistprovidesaworstcaseformanysearchalgorithms.

Considertwoalgorithms:

oneiscalled“sequentialsearch”whichscansthroughthelistfromlefttoright;andtheotheris“binarysearch”whichisgivenonpage24(Figure2.9)ofyourtextbook.Yourtasksare:

(1)Implementaniterativeversionandarecursiveversionofsequentialsearch;

(2)Implementaniterativeversionofbinarysearch;

(3)Analyzetheworstcasecomplexitiesoftheabovetwoversionsofsequentialsearchandthatofbinarysearch;

(4)Measureandcomparetheworstcaseperformancesoftheabovethreefunctionsfor

N=100,500,1000,2000,4000,6000,8000,10000.

Tomeasuretheperformanceofafunction,wemayuseC’sstandardlibrarytime.hasthefollowing:

Note:

Ifafunctionrunssoquicklythatittakeslessthanaticktofinish,wemayrepeatthefunctioncallsforKtimestoobtainatotalruntime(“TotalTime”),andthendividethetotaltime

byK

toobtainamoreaccurateduration(“Duration”)forasinglefunofthefunction.The

repetitionfactormustbylargeenoughsothatthenumberofelapsedticksisatleast10ifwewantanaccuracyofatleast10%.

Thetestresultsmustbelistedinthefollowingtable:

Theperformancesofthethreefunctionsmustbeplottedinthesame

N-run_timecoordinate

system for illustration.

3.2Project2:

ImplementationofLists,andPolynomial

Problems

1.Mergetwoorderedlistsintoanewlinkedlistinwhichthenodesarealsointhisorder.Iflengthsoforiginaltwolistsaremandn,thelengthofnewlinkedlistism+n.

Forexample:

Input:

5(lengthoflist1)

4 26 46 56 95

11(lengthoflist2)

15 17 26 30 46 48 56 58 82 90 95

Output:

4 15 17 26 30 46 48 56 58 82 90 95

Demands:

(1).Youshouldusesinglelinkedlist(withaheader)tocreatethefunctionsMakeEmpty,IsEmpty,IsLast,Find,Delete,FindPrevious,Insert,DeleteList,Header,First,Advance,Retrieve(SeeP40,Figure3.6).

(2).Usingabovefunctionstosolvethisproblem.

(3).Thelinkedimplementationoflistshouldbewritteninseparatedfiles(.cppand.h)intheVC++workspace.Theirnamesshouldbelinkedlist.h,linkedlist.cpp,merge.cpp.

2.ThedeclarationsthatfollowgiveusthepolynomialADT.StructurePolynomialis

Object:

P(x)=axe1+L+axen;asetoforderedpairsof

whereais

1

thecoefficientandei

Operations:

n i

istheexponent.eiarenonnegativeintegers.

Forallpoly,poly1,poly2∈Polynomial,coef∈Coefficients,expon∈ExponentsPolynomialZero() :

:

=returnthepolynomial,P(x)=0

BooleanIsZero(poly) :

:

=if(poly)returnFALSE;

elsereturnTRUE;

CoefficientCoef(poly,expon) :

:

=if(expon∈poly)returnitscoeffient

elsereturnzero.

ExponentLead_Exp(poly) :

:

=returnthelargestexponentinpoly.

PolynomialAttach(poly,coef,expon) :

:

=if(expon∈poly)returnerror

elsereturnthepolynomialpolywiththeterm

inserted.

PolynomialRemove(poly,expon) :

=if(expon∈poly)returnthepolynomialpolywith

thetermwhoseexponentisexpondeleted

elsereturnerror.

PolynomialSingleMult(poly,coef,expon):

=returnthepolynomialpoly*coef*xexpon

PolynomialAdd(poly1,poly2) :

=returnthepolynomialpoly1+poly2.PolynomialMult(poly1,poly2) :

=returnthepolynomialpoly1*poly2.endPolynomial

Demands:

(1).YoushouldchooseasuitablerepresentationforPolynomial.

(2).YoushouldcreatethefunctionsZero,IsZero,Coef,Lead_Exp,Attach,Remove,SingleMult,Add,Mult,andtestthem.

(3).If

A(x)=3x20+2x5+4andB(x)=3x4+2x3+3x2+1,writeafunctiontouseabove

functionstocomputeC(x)=A(x)+B(x)andD(x)=A(x)*B(x).

(4).Analyzeadvantagesofyourrepresentation.

(5).TheimplementationofpolynomialADTshouldbewritteninseparatedfiles(.cppand.h)intheVC++workspace.TheirnamesshouldbePolynomial.h,Polynomial.cpp,main.cpp.

Note:

Yourprogrammustreadfromafile“input.txt”andwritetoafile“output.txt”inthecurrentdirectory.

3.3Project3:

ImplementationandApplicationsofStacks

Problems

1.WriteaConversionfunctiontoconverseanydecimaldatatobinaryversion.

Demands:

(1).ImplementStackADTusinglinkedlistrepresentation,whichmustatleasthasfivebasicoperations:

Create,IsFull,Push,IsEmptyandPop.

(2).BuildanewprojecttoimplementtheConversionfunction.Theinputandoutputshouldbeaccordingtothefollowingformat:

Pleaseinputthedecimalnumber:

15

Thecorrespondingbinaryversionis:

1111

Pleaseinputthedecimalnumber:

-1

Bye!

2.Writeaprogramtojudgewhetherabracketsequence(maybehasotherletters)is“matching”.The“matching”meansthatifthereha

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

当前位置:首页 > 表格模板

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

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