资源描述:
《数据结构与算法分析 C语言描述(第2版)Larry Nyhoff 二叉树 课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1MainIndexContentsTreeStructuresTreeTerminologyBinaryTreeDefinitionDensityofaBinaryTreeBinaryTreeNodesBinaryScanAlgorithmsLeafCountandDepthDisplay/Copy/DeleteTreesChapter12–BinaryTreesSummarySlidesBinarySearchTreesLocatingDatainaTreeInsertOperationsRemovingaBinary
2、TreeNodestreeADTEraseOperationsstreeiteratorBinarySearchTreesApplication12MainIndexContentsTreeStructures23MainIndexContentsTreeStructures34MainIndexContentsTreeTerminology45MainIndexContentsTreeNodeLevelandPathLength5BinaryTreeDefinitionAbinarytreeTisafinitesetof
3、nodeswithoneofthefollowingproperties:(a)Tisatreeifthesetofnodesisempty.(Anemptytreeisatree.)(b)Thesetconsistsofaroot,R,andexactlytwodistinctbinarytrees,theleftsubtreeTLandtherightsubtreeTR.ThenodesinTconsistofnodeRandallthenodesinTLandTR.67MainIndexContentsDensity
4、ofaBinaryTree7CompletebinarytreeAcompletebinarytreeofdepthnisatreeinwhicheachlevelfrom0ton-1hasallpossiblenodesandallleafnodesatlevelnoccupytheleftmostpositionsinthetree.ThelargestpossiblebinarytreewithdepthnisonethatcontainsThedepthofacompletebinarytreethatholdst
5、henelementsis89MainIndexContentsTreeNodeLevelandPathLength–DepthDiscussion910MainIndexContentsTreeNodeLevelandPathLength–DepthDiscussion1011MainIndexContentsTreeNodeLevelandPathLength–DepthDiscussion1112MainIndexContentsTreeNodeLevelandPathLength–DepthDiscussion12
6、13MainIndexContentsBinaryTreeNodes13classtnodetemplateclasstnode{public://tnodeisaclassimplementationstructure.makingthe//datapublicsimplifiesbuildingclassfunctionsTnodeValue;tnode*left,*right;//defaultconstructor.datanotinitializedtnode(){}//initial
7、izethedatamemberstnode(constT&item,tnode*lptr=NULL,tnode*rptr=NULL):nodeValue(item),left(lptr),right(rptr){}};14FunctionbuildTree()tnode*buildTree(intn){tnode*root,*b,*c,*d,*e,*f,*g,*h,*i;switch(n){case0:d=newtnode('D');e=newtnode('E'
8、);b=newtnode('B',(tnode*)NULL,d);c=newtnode('C',e,(tnode*)NULL);root=newtnode('A',b,c);break;15FunctionbuildTree()case1:g=