- 浏览: 288214 次
- 性别:
- 来自: 广州
-
文章分类
最新评论
-
zlbdexiaohao:
book那个例子,我怎么获得osbn号
flex xml操作 -
mysh:
ui.localToGlobal(new Point(0, 0 ...
flex 组件绝对位置 -
hje:
http://help.adobe.com/en_US/Fla ...
杂记。 -
dbmonths:
dbmonths 写道dbmonths 写道brightACE ...
byteArray 操作 -
dbmonths:
dbmonths 写道brightACE 写道学习了,感谢分享 ...
byteArray 操作
public function walkTree(tree:Tree, item:Object, startAtParent:Boolean = false):void
{
// get the Tree's data descriptor
var descriptor:ITreeDataDescriptor = tree.dataDescriptor;
var cursor:IViewCursor;
var parentItem:Object;
var childItem:Object;
var childItems:Object;
// if the item is null, stop
if(item == null)
return;
// do we back up one level to the item's parent
if(startAtParent)
{
// get the parent
parentItem = tree.getParentItem(item);
// is the parent real
if(parentItem)
{
trace("|-- Parent Node ", parentItem[tree.labelField]);
// if the parent is a branch
if(descriptor.isBranch(parentItem))
{
// if the branch has children to run through
if(descriptor.hasChildren(parentItem))
{
// get the children of the branch
// this part of the algorithm contains the item
// passed
childItems = descriptor.getChildren(parentItem);
}
}
// if the branch has valid child items
if(childItems)
{
// create our back step cursor
cursor = childItems.createCursor();
// loop through the items parent's children (item)
while(!cursor.afterLast)
{
// get the current child item
childItem = cursor.current;
var label:String = childItem[tree.labelField];
var branch:Boolean = descriptor.isBranch(childItem);
// good place for a custom method()
trace("Sibling Nodes :: ", label, "Is Branch :: ", branch);
// if the child item is a branch
if(descriptor.isBranch(childItem))
// traverse the childs branch all the way down
// before returning
walkTree(tree, childItem);
// do it again!
cursor.moveNext();
}
}
}
}
else// we don't want the parent OR this is the second iteration
{
// if we are a branch
if(descriptor.isBranch(item))
{
// if the branch has children to run through
if(descriptor.hasChildren(item))
{
// get the children of the branch
childItems = descriptor.getChildren(item);
}
// if the child items exist
if(childItems)
{
// create our cursor pointer
cursor = childItems.createCursor();
// loop through all of the children
// if one of these children are a branch we will recurse
while(!cursor.afterLast)
{
// get the current child item
childItem = cursor.current;
var label:String = childItem[tree.labelField];
var branch:Boolean = descriptor.isBranch(childItem);
// good place for a custom method()
trace("-- Sub Node :: ", label, "Is Branch :: ", branch);
// if the child item is a branch
if(descriptor.isBranch(childItem))
// traverse the childs branch all the way down
// before returning
walkTree(tree, childItem);
// check the next child
cursor.moveNext();
}
}
}
}
}
2:使用
假设有个树,随便写一个:
<tree name="test">
<node name="a">
<d name="b"> </d>
<e name="c"> </e>
</node>
<node name="1"> </node>
<node name="I"> </node>
</tree>;
选择起始节点为name="a"的那个节点
用walkTree(tree对象, 起始节点)则
直接走下半部,不回溯期父节点,直接遍历a下子节点,结果就是遍历b,c
用walkTree(tree对象, 起始节点,true)则
先回溯到a的父,即test再遍历,结果就是遍历test,a,b,c,1,I
{
// get the Tree's data descriptor
var descriptor:ITreeDataDescriptor = tree.dataDescriptor;
var cursor:IViewCursor;
var parentItem:Object;
var childItem:Object;
var childItems:Object;
// if the item is null, stop
if(item == null)
return;
// do we back up one level to the item's parent
if(startAtParent)
{
// get the parent
parentItem = tree.getParentItem(item);
// is the parent real
if(parentItem)
{
trace("|-- Parent Node ", parentItem[tree.labelField]);
// if the parent is a branch
if(descriptor.isBranch(parentItem))
{
// if the branch has children to run through
if(descriptor.hasChildren(parentItem))
{
// get the children of the branch
// this part of the algorithm contains the item
// passed
childItems = descriptor.getChildren(parentItem);
}
}
// if the branch has valid child items
if(childItems)
{
// create our back step cursor
cursor = childItems.createCursor();
// loop through the items parent's children (item)
while(!cursor.afterLast)
{
// get the current child item
childItem = cursor.current;
var label:String = childItem[tree.labelField];
var branch:Boolean = descriptor.isBranch(childItem);
// good place for a custom method()
trace("Sibling Nodes :: ", label, "Is Branch :: ", branch);
// if the child item is a branch
if(descriptor.isBranch(childItem))
// traverse the childs branch all the way down
// before returning
walkTree(tree, childItem);
// do it again!
cursor.moveNext();
}
}
}
}
else// we don't want the parent OR this is the second iteration
{
// if we are a branch
if(descriptor.isBranch(item))
{
// if the branch has children to run through
if(descriptor.hasChildren(item))
{
// get the children of the branch
childItems = descriptor.getChildren(item);
}
// if the child items exist
if(childItems)
{
// create our cursor pointer
cursor = childItems.createCursor();
// loop through all of the children
// if one of these children are a branch we will recurse
while(!cursor.afterLast)
{
// get the current child item
childItem = cursor.current;
var label:String = childItem[tree.labelField];
var branch:Boolean = descriptor.isBranch(childItem);
// good place for a custom method()
trace("-- Sub Node :: ", label, "Is Branch :: ", branch);
// if the child item is a branch
if(descriptor.isBranch(childItem))
// traverse the childs branch all the way down
// before returning
walkTree(tree, childItem);
// check the next child
cursor.moveNext();
}
}
}
}
}
2:使用
假设有个树,随便写一个:
<tree name="test">
<node name="a">
<d name="b"> </d>
<e name="c"> </e>
</node>
<node name="1"> </node>
<node name="I"> </node>
</tree>;
选择起始节点为name="a"的那个节点
用walkTree(tree对象, 起始节点)则
直接走下半部,不回溯期父节点,直接遍历a下子节点,结果就是遍历b,c
用walkTree(tree对象, 起始节点,true)则
先回溯到a的父,即test再遍历,结果就是遍历test,a,b,c,1,I
发表评论
-
The Miner – 专业Flash AS3性能分析器(profiler)入门教程
2012-12-10 20:00 1479The Miner是由加拿大的Jean-Philippe Au ... -
as3
2011-10-11 14:43 1186loaderInfo.url.replace(/\\/g,'/ ... -
卡马克 滚屏
2011-09-25 21:58 974一些卡马克滚屏算法的例子,来源于网上。 -
as3 另外滚屏
2011-09-25 13:31 1236比较直接的思路是改变背景地图bitmap对象的x和y属性。 ... -
基元数据和复杂数据区别
2011-02-23 00:48 1339基元数据类型: 存放的是实际的值,赋值之后,相当于 ... -
死亡 白屏
2010-09-28 10:09 1059var arr:Array=[ 0.33,0.33 ... -
css demo
2010-09-10 12:34 1046/* CSS file */ /* Global { col ... -
css
2010-09-06 17:15 792Re:FLEX3中应用CSS完全详 ... -
flex mmorpg 地图编辑器demo
2010-07-16 15:04 1216简单的demo。。只实现基本功能。代码很少。。完整程序还在做。 ... -
as 的textField
2010-05-22 11:47 1555【关于TextField以垂直方 ... -
画图(扇形)
2010-03-24 14:30 1243private function init():void ... -
flex 封包
2010-02-24 14:43 1191接触了一段时间的网游 ... -
byteArray 操作
2010-02-24 11:37 2903这段时间在做socket, 当然就用到ByteArray了,O ... -
flex 生成swc
2010-02-21 15:08 2700flexbuilder打包swc地址: http://blog ... -
flex 嵌入html
2010-02-06 16:35 966public static function getHtmlF ... -
自己写的架构
2010-01-08 16:23 889111111111111 -
string帮助类
2010-01-07 16:32 929package com.hacker{ ... -
flex flash 相互调用
2009-12-17 14:39 4278flex 调用flash: private function ... -
flex pv3d 有用公式
2009-07-24 09:35 1759实用公式 统领全书,我们已经有了各种运动和效果的公式。 ... -
flex pv3d test
2009-07-24 09:21 2233<?xml version="1.0" ...
相关推荐
在IT领域,树是一种非常重要的数据结构,...通过理解和应用不同的遍历方法,开发者可以有效地处理树结构,执行诸如查找、排序、复制等任务。在实际项目中,了解并熟练掌握这些技巧对于编写高效且健壮的代码至关重要。
python xml.etree.ElementTree遍历xml所有节点 XML文件内容: 代码: #-*- coding: UTF-8 -*- # 从文件中读取数据 import xml.etree.ElementTree as ET #全局唯一标识 unique_id = 1 #遍历所有的节点
在实现TREE遍历功能时,这两个文件是必不可少的,需要在JSP页面中正确引入。 example4.js可能是一个包含具体TREE遍历逻辑的示例脚本。在EXT中,遍历TREE通常通过遍历TREE节点来完成,这可以通过EXT的API来实现。...
tree,ArrayList<tree>的创建与遍历插入 面试时可能会用到哦 1、根据 根节点rootId创建treeSize个子节点的tree树 2、根据list及父节点 列出父节点下的所有子节点 3、查找根节点 根据父节点找到对应的树 不足之处望...
VFP中TREE树遍历 无限制目录树
在`BinaryTree.c`和`Binary.h`这两个文件中,`BinaryTree.c`很可能是实现这些遍历方法的源代码,而`Binary.h`则可能包含了二叉树节点的定义和相关函数声明。在`BinaryTree.c`中,你可以找到如下的函数定义: - `...
在本实验中,我们主要探讨的是二叉树的遍历方法,这是数据结构中的一个重要概念。二叉树是一种特殊的树形数据结构,每个节点最多有两个子节点,通常分为左子节点和右子节点。二叉树遍历是访问二叉树中所有节点的过程...
一个类,可以遍历一个目录,将该目录下所有文件以及子目录及其文件都遍历,生成一个层次分明的数组,还可以将遍历的结果生成一个树状的字符串,直接echo到浏览器。 |-|a.txt |-|b.txt |-|c目录 |---|d.txt |---|c1...
本文主要讨论如何遍历和查找外部程序中Tree-View控件的项目。 首先,了解遍历Tree-View控件的基本原理。在Windows API中,可以通过发送消息来操作控件。对于Tree-View控件,有以下几个关键的消息: 1. TVM_...
二叉树是计算机科学中数据结构的一个重要概念,它是一种特殊的树形结构,每个节点最多有两个子节点,通常称为左...在实际编程中,根据不同的应用场景选择合适的二叉树结构和遍历方法,可以大大提高程序的效率和可读性。
在这个问题中,我们关注的是层次遍历、先根遍历和后根遍历这三种在树的遍历方法中的递归实现。接下来,我们将深入探讨这些概念以及如何在C++中通过函数实现它们。 首先,我们来看层次遍历,也称为宽度优先搜索(BFS...
在这个场景中,我们关注的是二叉树的遍历方法以及相关属性的计算。我们将深入探讨二叉树的先序、中序和后序遍历,以及如何计算二叉树的宽度、深度和节点关系。 **二叉树遍历** 1. **先序遍历**:这是二叉树遍历的...
在二叉树的遍历中,通常有三种主要的遍历方法:前序遍历、中序遍历和后序遍历。这些遍历方式都是基于二叉树的递归定义,即每个节点包含一个值、一个左子节点和一个右子节点。 1. **前序遍历(Preorder Traversal)**...
这两种遍历方法各有优劣,DFS在处理某些问题时可能更为节省空间,而BFS则常用于寻找最短路径。 接下来,我们讨论最小生成树(Minimum Spanning Tree, MST)。在加权无向图中,最小生成树是一棵树形子集,它包含原图...
4. **使用CFileFind遍历目录**:创建一个CFileFind对象,然后使用其FindFile()和FindNextFile()方法开始遍历目录。这些方法会找到当前目录下的所有文件和子目录。 5. **将文件和目录添加到树视图**:对于每个找到的...
在实际应用中,"tree-traversal-master"这个压缩包可能包含了一个关于二叉树遍历的项目,其中包括了实现这些遍历方法的源代码示例。通过学习和理解这些示例,你可以更好地掌握二叉树遍历的原理和技巧,从而在解决...
在Java编程中,有三种主要的遍历方法:前序遍历、中序遍历和后序遍历。 1. **前序遍历**(根-左-右): - 首先访问根节点。 - 然后递归地遍历左子树。 - 最后递归地遍历右子树。 2. **中序遍历**(左-根-右):...
"tree_反向层次遍历树_4321_"这个标题指的是一个特定的树遍历方法,即反向层次遍历(也称为反向深度优先搜索)。在标准的层次遍历(通常是从根节点开始,按照从上至下、从左至右的顺序访问节点)中,反向层次遍历则...
在本文中,我们将深入探讨两种遍历方法来实现赫夫曼编码:一种是基于栈的递归方法,另一种则是无栈的非递归方法。 首先,我们来理解赫夫曼树的基本构建过程。假设我们有一组字符及其对应的频率,如{'a': 3, 'b': 1,...