硬件学院 | 网络学院 | 游戏秘籍 | 求职技巧 | 企业管理 | 软件资讯 | IT导购 | 软件下载 | 源码下载
软件学院 | 安全资讯 | 图形图象 | 网络营销 | 电子商务 | 硬件资讯 | IT生活 | 教程下载 | 电影娱乐
网站首页    个人求职    单位招聘    高校联盟    猎头服务    培训服务    资讯中心    IT论坛
让每一个热爱IT的人都找到一份满意的工作!
文章搜索:
 您的位置首页->-> 软件学院-> .NET技术-> 数据结构与算法(C#实现)系列---N叉树(一)
数据结构与算法(C#实现)系列---N叉树(一)
作者:中国资讯网 来源:zixuen.com 加入时间:2005-5-12 www.cnitrc.com
数据结构与算法(C#实现)系列---N叉树(一)

Heavenkiller(原创)

N叉树的每一节点度数都相同,为N

using System;

using System.Collections;



namespace DataStructure

{

/// <summary>

/// NaryTree 的摘要说明。-----N叉树

/// </summary>

public class NaryTree:Tree

{

// member variables

protected object key;

protected uint degree;

protected ArrayList treeList=new ArrayList();

//protected uint height=0;//暂时默认为0



//create an empty tree whose attribute of degree is _degree

public NaryTree(uint _degree)

{

//

// TODO: 在此处添加构造函数逻辑

//

this.key=null;

this.degree=_degree;

this.treeList=null;

}

//构造一棵叶子结点的N叉树

public NaryTree(uint _degree,object _key)

{

this.key=_key;

this.degree=_degree;

this.treeList=new ArrayList();

this.treeList.Capacity=(int)_degree;



for(int i=0;i<this.treeList.Capacity;i++)

{



this.treeList.Add( this.GetEmptyInstance(_degree) );

}

}

//-----------------------------------------------------------------

protected virtual object GetEmptyInstance(uint _degree)

{ return new NaryTree(_degree); }

//-------------------------------------------------------------------

//judge whether the tree is an empty tree

public override bool IsEmpty()

{ return this.key==null; }

//判定是否是叶子结点。如果即不是空树且每一棵子树均为空树,则为叶子结点

public override bool IsLeaf()

{

if(IsEmpty())

return false;

for(uint i=0;i<this.degree;i++)

{

if( !(this[i].IsEmpty()) )

return false;

}

return true;

}

//-----------------------------------Inherited Attributes---------------------------------

public override object Key

{

get

{

return this.key;

}

}

//索引器

public override Tree this[uint _index]

{

get

{



if( _index>=this.degree )

throw new Exception("My:out of index!");//如果出界,则抛出异常

if( this.IsEmpty() )

return null;//如果是空树,则索引器返回一个 null

return (Tree)this.treeList[(int)_index];

}

set

{

this.treeList[(int)_index]=value;

}


  相关文章:
.NET技术
ASP技术
PHP技术
JSP技术
.NET技术
服务器技术
数据库技术
其它类
工具软件
办公软件
本类阅读TOP10
 
关于我们   |   服务声明   |   使用帮助   |   广告合作   |   网站地图   |   友情链接   |   加盟合作   |   联系我们
Copyright © 2006 cnitrc.com Inc. All Rights Reserved. 浙ICP备05074295号
中国IT人才网 版权所有 网络实名:中国IT人才
未经书面授权严禁转载和复制本站的任何招聘信息和文章