在写dbscan的时候用到了sortedlist,但是sortedlist不支持相同键的存储,可以使用以下办法。
using
System;
using System.Collections;
namespace testSortedList
{
class Class1
{
[STAThread]
static void Main( string [] args)
{
SortedList sl = new SortedList( new MySort()); //自定义排序类MySort,实现IComparer接口
sl.Add( 333 , 333 );
sl.Add( 111 , 111 );
sl.Add( 222 , 222 );
sl.Add( 111 , 112 );
PrintList(sl);
Console.ReadLine();
}
private static void PrintList(SortedList sl)
{
for ( int i = 0 ;i < sl.Count ;i ++ )
{
Console.WriteLine( " {0}/t{1} " ,sl.GetKey(i),sl.GetByIndex(i));
} // end for
} // end fn()
}
public class MySort:IComparer
{
#region IComparer 成员
public int Compare( object x, object y)
{
int iResult;
if((double)x > (double)y)
iResult = 1;
else
iResult = -1;
return iResult;
}
#endregion
}
}
using System.Collections;
namespace testSortedList
{
class Class1
{
[STAThread]
static void Main( string [] args)
{
SortedList sl = new SortedList( new MySort()); //自定义排序类MySort,实现IComparer接口
sl.Add( 333 , 333 );
sl.Add( 111 , 111 );
sl.Add( 222 , 222 );
sl.Add( 111 , 112 );
PrintList(sl);
Console.ReadLine();
}
private static void PrintList(SortedList sl)
{
for ( int i = 0 ;i < sl.Count ;i ++ )
{
Console.WriteLine( " {0}/t{1} " ,sl.GetKey(i),sl.GetByIndex(i));
} // end for
} // end fn()
}
public class MySort:IComparer
{
#region IComparer 成员
public int Compare( object x, object y)
{
int iResult;
if((double)x > (double)y)
iResult = 1;
else
iResult = -1;
return iResult;
}
#endregion
}
}