资源描述:
《数据结构的一道题(a problem of data structure)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、数据结构的一道题(Aproblemofdatastructure)Thebasicoperationofthe8584cyclequeueTimelimit:1000MSmemorylimit:1000KNumberofsubmission:3772passtimes:1884Questiontype:programminglanguage:UnlimitedDescriptionCreateanemptycircularqueue,andtherealizationoftheteam,theteam,theteamreturnedtothequeuelengthandre
2、turnsthefirstelement,queuetraversalalgorithm.Pleasecompletethefollowingprogram.#include#include#defineOK1#defineERROR0TypedefintStatus;//Statusisafunctiontype,itsvalueisafunctionofthestatecode,suchasOKetc.TypedefintQElemType;#defineMAXQSIZE//100(maximumqueuelengthforcirc
3、ularqueue,maximumqueuelengthtominus1)Typedefstruct{QElemType*base;//dynamicmemoryallocationinitializationIntfront;//pointerhead,ifthequeueisnotempty,pointingtotheheadofthequeueelementIntrear;//thetailpointer,ifthequeueisnotempty,pointingtothequeuetailelementsthenextposition}SqQueue;StatusI
4、nitQueue(SqQueue&Q){ToconstructaQ//emptyqueue,thequeueofpredefinedsizeisMAXQSIZEPleasecompletethecode//}StatusEnQueue(SqQueue&Q,QElemTypeE){E//insertelementsthetailelementsofthenewQPleasecompletethecode//}StatusDeQueue(SqQueue&Q,QElemType&e){//ifthequeueisnotempty,theteamheadelementoftheQi
5、sdeleted,ereturnsthevalue,andreturntoOK;otherwiseitreturnsERRORPleasecompletethecode//}StatusGetHead(SqQueueQ,QElemType&e){//ifthequeueisnotempty,thenuseereturntotheteamthefirstelement,andreturnsOK,otherwiseitreturnsERRORPleasecompletethecode//}IntQueueLength(SqQueueQ){//returnsthenumberof
6、elementsintheQPleasecompletethecode//}StatusQueueTraverse(SqQueueQ){//ifthequeueisnotempty,fromheadtotailteamfollowedbyalltheoutputqueueelement,andreturntoOK;otherwiseitreturnsERROR.Inti;I=Q.front;If(______________________)printf("TheQueueisEmpty!");//pleasefillintheblanksElse{Printf("TheQ
7、ueueis:");While(______________________)//pleasefillintheblanks{Printf("%d",______________________);//pleasefillintheblanksI=______________________;//pleasefillintheblanks}}Printf("");ReturnOK;}Intmain(){Inta;SqQueueS;QElemTypex,e;If(//______________________)