明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

數(shù)據(jù)結(jié)構(gòu)與算法(C#完成)系列---樹(3)

[摘要]數(shù)據(jù)結(jié)構(gòu)與算法(C#實(shí)現(xiàn))系列---樹(三) Heavenkiller(原創(chuàng)) //overwrite Object.Equals() --- reference type realization public override bool Equals(o...

數(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

    

     }

}