国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

數(shù)據(jù)結(jié)構(gòu)與算法(C#實現(xiàn))系列---N叉樹(二)

2024-07-21 02:20:05
字體:
供稿:網(wǎng)友
數(shù)據(jù)結(jié)構(gòu)與算法(c#實現(xiàn))系列---n叉樹(二)

heavenkiller(原創(chuàng))

public override uint degree

{

get

{

return this.degree;

}

}



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



//只用于空樹結(jié)點

public virtual void attachkey(object _obj)

{

if(!isempty())

throw new exception("my:this node must be a empty tree node!");

this.key=_obj;

this.treelist=new arraylist();//產(chǎn)生一個degree長的數(shù)組,并將其初始化為空樹

this.treelist.capacity=(int)this.degree;



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

{

treelist.add(new narytree(this.degree));

}

/*

foreach(object tmpobj in this.treelist)

{

tmpobj=new narytree(this.degree);

}

*/

}

//只用于葉子結(jié)點,將葉子結(jié)點變?yōu)橐粋€空結(jié)點,并返回葉子結(jié)點關(guān)鍵字的引用

public virtual object detachkey()

{

if(!isleaf())

throw new exception("my:this node must be a leaf node!");

object result=this.key;//store this leaf node temporary

this.key=null;

this.treelist=null;



return result;

}

//將子樹連接到指定樹的第num個結(jié)點上,前提是這個結(jié)點必須是空結(jié)點,并且度數(shù)相同,否則拋出異常

public virtual void attachsubtree(uint num,narytree _narytree)

{

if(this.isempty())

throw new exception("my:it can't be a empty tree!");

if(!(this[num-1].isempty()) | this.degree!=_narytree.degree )

throw new exception("my:this[i-1] must be empty and they should have the same degree!");

this[num-1]=_narytree;

}

//僅為非空樹定義,從給定樹中刪去它的第i棵子樹并連上一個空樹,度數(shù)相同,并且返回刪除的子樹引用

public virtual narytree detachsubtree(uint num)

{

if (isempty())

throw new exception("my:it can't be empty! ");

narytree tmptree=this;

((narytree)this[num-1]).key=null;

((narytree)this[num-1]).treelist=null;



return this;

}



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





}

}


國內(nèi)最大的酷站演示中心!
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 临沧市| 宁津县| 保亭| 新蔡县| 宜州市| 五指山市| 平舆县| 潍坊市| 清远市| 韶关市| 佳木斯市| 东明县| 雷州市| 墨竹工卡县| 英超| 旺苍县| 台江县| 滕州市| 东台市| 陕西省| 华坪县| 庆城县| 丰镇市| 丰都县| 江孜县| 自贡市| 准格尔旗| 大新县| 甘洛县| 保靖县| 灵台县| 岗巴县| 九寨沟县| 竹北市| 苏尼特右旗| 兴和县| 灵寿县| 县级市| 河曲县| 盈江县| 新巴尔虎右旗|