AS3 BianryTreeNode类-用于树数据集合
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3 BianryTreeNode类-用于树数据集合相关的知识,希望对你有一定的参考价值。
package { import flash.display.Sprite; /********************************************************************************************** * BinaryTreeNode Class - Designed to give generic object functionality to a binary tree * * node type. * * @author : Richard Vacheresse /| http://www.rvacheresse.com /| * * Licensed for free Commercial and Private use creative commons license agreement. * * The provided code is in an "as-is" state. Richard Vacheresse makes no warranties * * regarding the provided code, and disclaims liability for damages resulting from its use. * * I am also not responsible for baby Smurfs being born only on a blue moon; the way your * * father looks really creeepy like at one of your friends; or for your better half being home * * late last Tuesday night, but man-oh-man she can sure dance. I am most importantly not * * responsible for you reading this far in docs, really? * * @version 1.0 * **********************************************************************************************/ public class BinaryTreeNode extends Sprite { private var element:Sprite; private var left:BinaryTreeNode; private var right:BinaryTreeNode; /** * BinaryTreeNode(obj:Object):void Constructor. Creates a new * tree node with the specified data element being passed to it. * @param - Sprite Object **/ public function BinaryTreeNode(obj:Sprite):void { element = obj; left = null; right = null; trace(" Binary Tree Node Created"); } /** * numChildren():int - Returns the number of non-null children of this node. * This method may be able to be written more efficiently. * @return the integer number of non-null children of this node **/ public function getNumChildren():int { var children:int = 0; if(left != null) children = (1 + left.getNumChildren()); else if(right != null) children += (1 + right.getNumChildren()); return children; } /** * toString():String function - Returns a string representation of the * node and its children. * @return - String Object **/ override public function toString():String { var result:String = ""; result = (" Binary Tree Node: " + " -----------------"+ " The Main Element is: " + this.element.toString()); if(this.getNumChildren() > 0) { try { if(this.left != null) result += (" The Left is: " + this.left.toString()); if(this.right != null) result += (" The Right is: " + this.right.toString()); } catch(er:Error) { trace("Error Caught: " + er); } } return result; } //$------------------------------------------- //$ $-SETTERS-$ //$------------------------------------------- /** * setElement(spr:Sprite):void function - Sets the element property to passed value. **/ public function setElement(spr:Sprite):void { this.element = spr; trace(" Main Element Set to: " + spr); } /** * setLeftNode(btNode:BinaryTreeNode):void function - Sets the left binary tree node * property to passed value. **/ public function setLeftNode(btNode:BinaryTreeNode):void { this.left = btNode; trace(" Left Node Set To: " + btNode); } /** * setRightNode(btNode:BinaryTreeNode):void function - Sets the right binary tree node * property to passed value. **/ public function setRightNode(btNode:BinaryTreeNode):void { this.right = btNode; trace(" Right Node Set To: " + btNode); } //$------------------------------------------- //$ $-GETTERS-$ //$------------------------------------------- /** * getElement():Sprite function - Returns the element property value. * @return - Sprite Object **/ public function getElement():Sprite { return this.element; trace(" Main Element Returned: " + spr); } /** * getLeftNode():BinaryTreeNode function - Returns the left binary tree node * property. * @return - BinaryTreeNode Object **/ public function getLeftNode():BinaryTreeNode { reuturn this.left; trace(" Left Node Returned: " + btNode); } /** * getRightNode():BinaryTreeNode function - Returns the right binary tree node * property. * @return - BinaryTreeNode Object **/ public function getRightNode():BinaryTreeNode { return this.right; trace(" Right Node Returned: " + btNode); } } }
以上是关于AS3 BianryTreeNode类-用于树数据集合的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 用于格式化日期的AS3类,如PHP函数日期
用于导入的 AS3 SoundChannel/Sound HZ 限制