Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / C#

Back to Basics - Generic Data Structures and Algorithms In .NET 2.0

Rate me:
Please Sign up or sign in to vote.
4.96/5 (93 votes)
23 Apr 2007Ms-PL15 min read 279.5K   2.6K   300  
Implementations of generic data structures and algorithms in .NET 2.0.
using System;
using System.Collections.Generic;
namespace DataStructuresDotNet.DataStructures
{
	/// <summary>
	///  An interface for a Bag data structure.
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public interface IBag<T>
	{

		/// <summary>
		/// Adds n * the specified item to the bag.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="amount">The amount.</param>
		void Add(T item, int amount);

		/// <summary>
		/// Applies the Difference operation on two bags.
		/// </summary>
		/// <param name="bag">The other bag.</param>
		/// <returns></returns>
		IBag<T> Difference(IBag<T> bag);

		/// <summary>
		/// Applies the Intersection opertion on two bags.
		/// </summary>
		/// <param name="bag">The other bag.</param>
		/// <returns></returns>
		IBag<T> Intersection(IBag<T> bag);

		/// <summary>
		/// Determines whether the specified bag is equal to this instance.
		/// </summary>
		/// <param name="bag">The bag to compare.</param>
		/// <returns>
		/// 	<c>true</c> if the specified bag is equal; otherwise, <c>false</c>.
		/// </returns>
		bool IsEqual(IBag<T> bag);

		/// <summary>
		/// Removes the specified amount of items from the bag.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <param name="max">The maximum amount of items to remove.</param>
		/// <returns></returns>
		bool Remove(T item, int max);

		/// <summary>
		/// Gets the count of the specified item contained in the bag.
		/// </summary>
		/// <value></value>
		int this[T item] { get; }

		/// <summary>
		/// Applies the Union operation with two bags.
		/// </summary>
		/// <param name="bag">The other bag.</param>
		/// <returns></returns>
		IBag<T> Union(IBag<T> bag);
	}
}

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 Microsoft Public License (Ms-PL)


Written By
Web Developer
South Africa South Africa
The author is a software consultant in South Africa, specializing in bespoke software solutions.

Comments and Discussions