实验二 栈和队列的基本操作实现及其应用_第1页
实验二 栈和队列的基本操作实现及其应用_第2页
实验二 栈和队列的基本操作实现及其应用_第3页
实验二 栈和队列的基本操作实现及其应用_第4页
实验二 栈和队列的基本操作实现及其应用_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验二栈和队列的基本操作实现及其应用一、实验目的1、熟练掌握栈和队列的基本操作在两种存储结构上的实现。2、会用栈和队列解决简单的实际问题。二、实验内容(可任选或全做)题目一、试写一个算法,判断依次读入的一个以@为结束符的字符序列,是否为回文。所谓“回文“是指正向读和反向读都一样的一字符串,如“321123”或“ableelba”相关常量及结构定义:#defineSTACK_INIT_SIZE100#defineSTACKINCREMENT10#defineOK1#defineERROR0typedefintSElemType;//栈类型定义typedefstructSqStack {SElemType*base;SElemType*top;intstacksize;}SqStack;设计相关函数声明:判断函数:intIsReverse()栈:intInitStack(SqStack&S)intPush(SqStack&S,SElemTypee)intPop(SqStack&S,SElemType&e)intStackEmpty(s)题目二、编程模拟队列的管理,主要包括:出队列、入队、统计队列的长度、查找队列某个元素e、及输出队列中元素。[实现提示]:参考教材循环队列的有关算法,其中后两个算法参考顺序表的实现。题目三、RailsDescriptionThereisafamousrailwaystationinPopPush

ThelocaltraditionisthateverytrainarrivingfromthedirectionAcontinuesinthedirectionBwithcoachesreorganizedinsomeway.AssumethatthetrainarrivingfromthedirectionAhasN<=1000coachesnumberedinincreasingorder1,2,...,N.ThechieffortrainreorganizationsmustknowwhetheritispossibletomarshalcoachescontinuinginthedirectionBsothattheirorderwillbea1,a2,...,aN.Helphimandwriteaprogramthatdecideswhetheritispossibletogettherequiredorderofcoaches.YoucanassumethatsinglecoachescanbedisconnectedfromthetrainbeforetheyenterthestationandthattheycanmovethemselvesuntiltheyareonthetrackinthedirectionB.Youcanalsosupposethatatanytimetherecanbelocatedasmanycoachesasnecessaryinthestation.ButonceacoachhasenteredthestationitcannotreturntothetrackinthedirectionAandalsoonceithasleftthestationinthedirectionBitcannotreturnbacktothestation.InputTheinputconsistsofblocksoflines.Eachblockexceptthelastdescribesonetrainandpossiblymorerequirementsforitsreorganization.InthefirstlineoftheblockthereistheintegerNdescribedabove.Ineachofthenextlinesoftheblockthereisapermutationof1,2,...,N.Thelastlineoftheblockcontainsjust0.

Thelastblockconsistsofjustonelinecontaining0.OutputTheoutputcontainsthelinescorrespondingtothelineswithpermutationsintheinput.AlineoftheoutputcontainsYesifitispossibletomarshalthecoachesintheorderrequiredonthecorrespondinglineoftheinput.OtherwiseitcontainsNo.Inaddition,thereisoneemptylineafterthelinescorrespondingtooneblockoftheinput.Thereisnolineintheoutputcorrespondingtothelast``null''blockoftheinput.SampleInput512345541230665432100SampleOutputYesNoYes题目四、SlidingWindowDescriptionAnarrayofsizen≤106isgiventoyou.Thereisaslidingwindowofsizekwhichismovingfromtheveryleftofthearraytotheveryright.Youcanonlyseetheknumbersinthewindow.Eachtimetheslidingwindowmovesrightwardsbyoneposition.Followingisanexample:

Thearrayis[1

3

-1

-3

5

3

6

7],andkis3.WindowpositionMinimumvalueMaximumvalue[1

3

-1]

-3

5

3

6

7

-13

1

[3

-1

-3]

5

3

6

7

-33

1

3

[-1

-3

5]

3

6

7

-35

1

3

-1

[-3

5

3]

6

7

-35

1

3

-1

-3

[5

3

6]

7

36

1

3

-1

-3

5

[3

6

7]37Yourtaskistodeterminethemaximumandminimumvaluesintheslidingwindowateachposition.InputTheinputconsistsoftwolines.Thefirstlinecontainstwointegersnandkwhicharethelengthsofthearrayandtheslidingwindow.Therearenintegersinthesecondline.OutputTherearetwolinesintheoutput.Thefirstlinegivestheminimumvaluesinthewindowateachposition,fromlefttoright,respectively.Thesecondlinegivesthemaximumvalues.SampleInput8313-1-35367SampleOutput-1-3-3-333335567题目五(选作考查串知识)DNAEvolution【Description】Evolutionisaseeminglyrandomprocesswhichworksinawaywhichresemblescertainapproachesweusetogetapproximatesolutionstohardcombinatorialproblems.Youarenowtodosomethingcompletelydifferent.GivenaDNAstringSfromthealphabet{A,C,G,T},findtheminimalnumberofcopyoperationsneededtocreateanotherstringT.Youmayreversethestringsyoucopy,andcopybothfromSandthepiecesofyourpartialT.Youmayputthesepiecestogetheratanytime.YoumayonlycopycontiguouspartsofyourpartialT,andallcopiedstringsmustbeusedinyourfinalT.Example:FromS=“ACTG”createT=“GTACTAATAAT”GetGT.........bycopyingandreversing"TG"fromS.GetGTAC...bycopying"AC"fromS.GetGTACTA…..bycopying"TA"fromthepartialT.GetGTACTAATbycopyingandreversing"TA"fromthepartialT.GetGTACTAATAATbycopying"AAT"fromthepartialT.【Input】Thefirstlineofinputgivesasingleinteger,1≤k≤10,thenumberoftestcases.Thenfollow,foreachtestcase,alinewiththestringS,lengthofSislessthen19,andalinewiththestringT,lengthofTislessthen19.【Output】OutputforeachtestcasethenumberofcopyoperationsneededtocreateTfromS,or"impossible"ifitcannotbedone.【SampleInput】4ACGTTGCAACACGTTCGATCGAAAAAAAAAAAAAAAAAAAA【Sampleoutput】1impossible46题目六(选作考查数组知识)MagicSquares描述Followingthesuccessofthemagiccube,Mr.Rubikinventeditsplanarversion,calledmagicsquares.Thisisasheetcomposedof8equal-sizedsquares:12348765Inthistaskweconsidertheversionwhereeachsquarehasadifferentcolor.Colorsaredenotedbythefirst8positiveintegers.Asheetconfigurationisgivenbythesequenceofcolorsobtainedbyreadingthecolorsofthesquaresstartingattheupperleftcornerandgoinginclockwisedirection.Forinstance,theconfigurationofFigure3isgivenbythesequence(1,2,3,4,5,6,7,8).Thisconfigurationistheinitialconfiguration.Threebasictransformations,identifiedbytheletters`A',`B'and`C',canbeappliedtoasheet:'A':exchangethetopandbottomrow,'B':singlerightcircularshiftingoftherectangle,'C':singleclockwiserotationofthemiddlefoursquares.Belowisademonstrationofapplyingthetransformationstotheinitialsquaresgivenabove:A:87651234B:41235876C:17248635Allpossibleconfigurationsareavailableusingthethreebasictransformations.Youaretowriteaprogramthatcomputesaminimalsequenceofbasictransformationsthattransformstheinitialconfigurationabovetoas

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论