码迷,mamicode.com
首页 >  
搜索关键字:cc150    ( 107个结果
CC150 4.6
4.6Designanalgorithmandwritecodetofindthefirstcommonancestoroftwonodesinabinarytree.Avoidstoringadditionalnodesinadatastructure.NOTE:Thisisnotnecessarilyabinarysearchtree.BTNodefind(Noden,Nodea,Nodeb) { if(n==a||n==b) { returnn; } intnodeMatch=nodeMatch(a...
分类:其他好文   时间:2014-11-27 08:02:42    阅读次数:180
CC150 3.3
3.3Imaginea(literal)stackofplates.Ifthestackgetstoohigh,itmighttopple.Therefore,inreallife,wewouldlikelystartanewstackwhenthepreviousstackexceedssomethreshold.ImplementadatastructureSetOfStacksthatmimicsthis.SetOfStacksshouldbecomposedofseveralstacks,andsho..
分类:其他好文   时间:2014-11-25 02:01:22    阅读次数:201
CC150 3.4
3.4IntheclassicproblemoftheTowersofHanoi,youhave3rodsandNdisksofdifferentsizeswhichcanslideontoanytower.Thepuzzlestartswithdiskssortedinascendingorderofsizefromtoptobottom(e.g.,eachdisksitsontopofanevenlargerone).Youhavethefollowingconstraints:(A)Onlyonedis..
分类:其他好文   时间:2014-11-25 02:00:22    阅读次数:115
CC150 3.1
3.1Describehowyoucoulduseasinglearraytoimplementthreestacks.3stacks?separatethearrayinto3sections.Use3index.push(intstack,Tt) { validateStackNum(stack);//Validate(stack>=0&&stack<2); intpos=stackPos[stack]; check(pos+1);//ifexceeds,enlargeth..
分类:其他好文   时间:2014-11-24 12:09:27    阅读次数:161
CC150 3.2
3.2Howwouldyoudesignastackwhich,inadditiontopushandpop,alsohasafunctionminwhichreturnstheminimumelement?Push,popandminshouldalloperateinO(1)time.Useanotherstackmaintainingmin. push(Tt) { mainStack.push(t); TcurMin=minStack.peek(); if(curMin==null||t<curM..
分类:其他好文   时间:2014-11-24 12:08:38    阅读次数:183
CC150 2.3
2.3Implementanalgorithmtodeleteanodeinthemiddleofasinglelinkedlist,givenonlyaccesstothatnode.EXAMPLEInput:thenode‘c’fromthelinkedlista->b->c->d->eResult:nothingisreturned,butthenewlinkedlistlookslikea->b->d->eItseemscannotdirecltydele..
分类:其他好文   时间:2014-11-24 08:45:39    阅读次数:106
CC150 2.2
2.2Implementanalgorithmtofindthenthtolastelementofasinglylinkedlist.//Assumetheinputlisthasnocircle. //O(n) NodefindNthNodeToLast(Noderoot,intn) { //Findsize Noden=root; intsize=0; while(n!=null) { size++; n=n.next; } if(n>size) returnnull; intnFromThe..
分类:其他好文   时间:2014-11-24 08:44:50    阅读次数:126
CC150 2.5
2.5Givenacircularlinkedlist,implementanalgorithmwhichreturnsnodeatthebeginningoftheloop.DEFINITIONCircularlinkedlist:A(corrupt)linkedlistinwhichanode’snextpointerpointstoanearliernode,soastomakealoopinthelinkedlist.EXAMPLEinput:A->B->C->D->E-&g..
分类:其他好文   时间:2014-11-24 08:44:00    阅读次数:122
CC150 2.4
2.4Youhavetwonumbersrepresentedbyalinkedlist,whereeachnodecontainsasingledigit.Thedigitsarestoredinreverseorder,suchthatthe1’sdigitisattheheadofthelist.Writeafunctionthataddsthetwonumbersandreturnsthesumasalinkedlist.EXAMPLEInput:(3->1->5)+(5->9-&..
分类:其他好文   时间:2014-11-24 08:43:11    阅读次数:120
cc150:实现一个算法来删除单链表中间的一个结点,只给出指向那个结点的指针
实现一个算法来删除单链表中间的一个结点,只给出指向那个结点的指针。...
分类:编程语言   时间:2014-11-14 19:48:54    阅读次数:199
107条   上一页 1 ... 7 8 9 10 11 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!