以前写的一个遍历算法,以后也应该用得着(89) |
|
/*
* @author 於良伟
* 根先序遍历算法
* @param bizes 所选的遍历总数据
* @param bizID 当前遍历的根节点id
* @param treeList 遍历返回结果
* @return void
*
* */
private void traversal(List bizes,Long bizID, List treeList) {
for (int i = 0; i < bizes.size(); i++) {
Business business = (Business) bizes.get(i);
if (business.getParentBusiness()!=null && bizID.equals(business.getParentBusiness().getId())) {
/*如果当前节点存在父节点并且当前节点的父节点编号与bizID相同,则添加到treeList*/
treeList.add(business);
/*遍历*/
traversal(bizes,business.getId(),treeList);
}
} //for
}
/*
* @author 於良伟
* 根据所选收支类型创建树
* @param biz 所选节点
* @param IOflag 收支类型
* @return List treeList
*
*
* */
public List builderTreeByBiz(final Business biz,final Integer IOflag){
/*从指定节点构造收支类型树结构的List*/
List treeList = new ArrayList();
if (biz==null) {
/*如果biz为空,返回空List*/
return treeList;
}
/*添加biz到treeList*/
treeList.add(biz);
/*根先序遍历*/
traversal(getBusinessByDepartment(biz.getDept(),IOflag),biz.getId(),treeList);
return treeList;
}
|
posted on 2007-09-27 18:58
Crying 阅读(226)
评论(0) 编辑 收藏 所属分类:
算法