简单的数据移动算法(C#)
2009-04-14 08:24:52 来源:WEB开发网详细的代码下载下面的代码项目进行了解。
测试DEMO:
/// <summary>
/// 向上移动
/// </summary>
private static void StartTestDataStructMoveUp()
{
Console.WriteLine("-------------待排序的数据--------------");
List<MoveSeqArithmeticItem<object, string>> list = new List<MoveSeqArithmeticItem<object, string>>();
for (int i = 0; i < 10; i++)
{
MoveSeqArithmeticItem<object, string> o = new MoveSeqArithmeticItem<object, string>(i, string.Format("key{0}", i), null);
list.Add(o);
}
//构造数据结构,并加入数据
MoveSeqArithmetic<object, string> s = new MoveSeqArithmetic<object, string>(list.ToArray<MoveSeqArithmeticItem<object, string>>());
//向上移动数据
s.MoveUpByKeys(new object[] { "key0" });
s.MoveUpByKeys(new object[] { "key2", "key3", "key4" });
s.MoveUpByKeys(new object[] { "key9" });
//打印
foreach (MoveSeqArithmeticItem<object, string> item in s.ArrList)
{
Console.WriteLine(string.Format("Seq: {0} --- Key: {1}", item.Seq, item.ObjKey));
}
}
执行结果上面已经展示。
更多精彩
赞助商链接