Click here to Skip to main content
15,885,951 members
Articles / Programming Languages / C#

Red-Black Trees in C#

Rate me:
Please Sign up or sign in to vote.
4.82/5 (30 votes)
14 Sep 2004CPOL8 min read 255.8K   5.9K   86  
A C# implementation of a Red-Black Tree.
using System;

namespace Test
{
	//
	// demonstrates using a key as a separate object
	//
	
	public class MyKey : IComparable
	{
		private int intMyKey;
		public	int Key
		{
			get
			{
				return intMyKey;
			}
			
			set
			{
				intMyKey = value;
			}
		}
		
		public MyKey(int key) 
		{
			intMyKey = key;
		}
		
		public int CompareTo(object key)
		{
			if(Key > ((MyKey)key).Key)
				return 1;
			else
				if(Key < ((MyKey)key).Key)
				return -1;
			else
				return 0;
		}

		public override string ToString()
		{
			return intMyKey.ToString();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
Roy is a software developer who digs all aspects of software development, from design and architecture to implementation.

Comments and Discussions