This library provides a very nice and flexible package of sorting algorithms from which the developer can choose.
|
using System;
using System.Collections;
namespace NSort
{
/// <summary>
/// Abstract base class for Swap sort algorithms.
/// </summary>
/// <remarks>
/// <para>
/// This class serves as a base class for swap based sort algorithms.
/// </para>
/// </remarks>
public abstract class SwapSorter : ISorter
{
private IComparer comparer;
private ISwap swapper;
public SwapSorter()
{
this.comparer = new ComparableComparer();
this.swapper = new DefaultSwap();
}
public SwapSorter(IComparer comparer, ISwap swapper)
{
if (comparer == null)
throw new ArgumentNullException("comparer");
if (swapper==null)
throw new ArgumentNullException("swapper");
this.comparer = comparer;
this.swapper = swapper;
}
/// <summary>
/// Gets or sets the <see cref="IComparer"/> object
/// </summary>
/// <value>
/// Comparer object
/// </value>
/// <exception cref="ArgumentNullException">
/// Set property, the value is a null reference
/// </exception>
public IComparer Comparer
{
get
{
return this.comparer;
}
set
{
if (value==null)
throw new ArgumentNullException("comparer");
this.comparer = value;
}
}
/// <summary>
/// Gets or set the swapper object
/// </summary>
/// <value>
/// The <see cref="ISwap"/> swapper.
/// </value>
/// <exception cref="ArgumentNullException">Swapper is a null reference</exception>
public ISwap Swapper
{
get
{
return this.swapper;
}
set
{
if (value==null)
throw new ArgumentNullException("swapper");
this.swapper = value;
}
}
public abstract void Sort(IList list);
}
}
|
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.
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.