顺序表是在计算机内存中以数组的形式保存的线性表,是指用一组地址连续的存储单元依次存储数据元素的线性结构。 单向链表是链表的一种,其特点是链表的链接方向是单向的,对链表的访问要通过顺序读取从头部开始。 双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继和直接前驱。所以,从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点。下面的代码中了解一下Snake.Net中的线性表
namespace Eastasp.Framework.Collections

{
namespace#region namespace
using System;
using System.Collections;
using Collections;
using Diagnostics;
using Utility;
using NUnit.Framework;
#endregion

class for CollectionTest#region class for CollectionTest
/**//// <summary>
/// Summary description for CollectionTest.
/// </summary>
[TestFixture]
public class CollectionTest:ITest
{
public CollectionTest()
{
}
[Test]
public void Test()
{
OutputLinks();
}
PRivate void OutputLinks()
{
//declare
ILink[] links;
//output start infomation
Console.Write("------- Starttest Links -------{0}{0}{0}", StringUtil.CrLf);

links = new ILink[]
{
new OrderedTable(),
new SingleLink(),
new DoubleLink()};

for(int i = 0; i < links.Length; i++)
{
Console.Write("Start Test {0} {1}", links[i].GetType().FullName, StringUtil.CrLf);
OutputLink(links[i]);
Console.Write("Test Completed{1}{1}", links[i].GetType().FullName, StringUtil.CrLf);
}
//output end infomation
Console.Write("{0}{0}------- End test Links -------{0}{0}", StringUtil.CrLf);
}
private void OutputLink(ILink link)
{
//declare
object[] array;
DateTime start;
DateTime end;
TimeSpan passed;
start = DateTime.Now;
Console.Write(String.Format("Start date time:{0}{1}", start.ToString("MM/dd/yyyy HH:mm:ss"), StringUtil.CrLf));

for(int i = 0; i < 10000; i++)
{
link.Clear();
//initialize
array = new object[]
{"aaa", "bbb", "ccc", "ddd", "eee", "hhh", "fff", "ggg", "bb2", "cc2", "dd2", "ee2", "hh2", "ff2", "gg2", "iii", "jjj", "kkk"};
link.AddRange(array);
Assert.AreEqual(link.Count, array.Length, "Error!");
link.Add("000");
Assert.AreEqual(link.Count, array.Length + 1, "Error!");
link.Remove("ddd");
Assert.AreEqual(link.Count, array.Length, "Error!");
link.Insert(3, "222");
Assert.AreEqual(link.Count, array.Length + 1, "Error!");
link.RemoveAt(2);
Assert.AreEqual(link.Count, array.Length, "Error!");
}
end = DateTime.Now;
passed = new TimeSpan(end.Ticks - start.Ticks);
Console.Write(String.Format("End date time:{0}{1}", end.ToString("MM/dd/yyyy HH:mm:ss"), StringUtil.CrLf));
Console.Write(string.Format("spend {0} seconds, {1} milliseconds {2}", passed.Seconds, passed.Milliseconds, StringUtil.CrLf));
}
}
#endregion
}
namespace Eastasp.Framework.Collections

{
namespace#region namespace
using System;
using System.Collections;
using Collections;
using Diagnostics;
using Utility;
using NUnit.Framework;
#endregion

class for CollectionTest#region class for CollectionTest
/**//// <summary>
/// Summary description for CollectionTest.
/// </summary>
[TestFixture]
public class CollectionTest:ITest
{
public CollectionTest()
{
}
[Test]
public void Test()新闻热点
疑难解答