數(shù)據(jù)結(jié)構(gòu)與算法(c#實(shí)現(xiàn))系列---樹(三)
heavenkiller(原創(chuàng))
//overwrite object.equals() --- reference type realization
public override bool equals(object _obj)
{
if( _obj==null )
return false;//因?yàn)閠his不可能為null
if( ! (this.gettype()==_obj.gettype()) )
return false;//類型不相等也不相等
tree tmpobj=(tree)_obj;
//比較引用成員
if( !object.equals(this.key,tmpobj.key) )
return false;
//比較值類型成員
if( !this.degree.equals(tmpobj.degree) )
return false;
//if( !this.height.equals(tmpobj.height) )
//return false;
return true;
}
//在此重載 ==,!= 后, 在以后繼承的類中不必實(shí)現(xiàn)了
public static bool operator==(tree _treea,tree _treeb)
{
return object.equals(_treea,_treeb);
}
public static bool operator!=(tree _treea,tree _treeb)
{
return !(_treea==_treeb);
}
#region icomparable 成員
public virtual int compareto(object obj)
{
// todo: 添加 tree.compareto 實(shí)現(xiàn)
return 0;
}
#endregion
}
}
中國最大的web開發(fā)資源網(wǎng)站及技術(shù)社區(qū),新聞熱點(diǎn)
疑難解答
圖片精選