Data structure and algorithm (C # Implementation) Series---tree (iii)

Source: Internet
Author: User
Data | structure | algorithm

Data structure and algorithm (C # Implementation) Series---tree (iii)

Heavenkiller (original)

Overwrite Object.Equals ()---reference type realization

public override bool Equals (object _obj)

{

if (_obj==null)

Return false;//because this cannot be null

if (! (This. GetType () ==_obj. GetType ()))

Return false;//types are not equal or equal

Tree tmpobj= (_obj);

Comparing reference members

if (! Object.Equals (this. Key,tmpobj.key))

return false;

Comparing value type members

if (!this. Degree.equals (Tmpobj.degree))

return false;

if (!this. Height.equals (Tmpobj.height))

return false;

return true;

}

After this overload is ==,!=, you do not have to implement in a class that inherits later

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 Members

public virtual int CompareTo (object obj)

{

TODO: Add Tree.compareto implementation

return 0;

}

#endregion

}

}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.