/// <summary> /// 遍历 /// </summary> public void Traverse() { StringBuilder sb = new StringBuilder(); for (LinkListIterator <T> iterator = Begin(); iterator != End(); ++iterator) { sb.Append(iterator.Element.ToString() + " "); } Console.WriteLine(sb.ToString()); }
public static void Test() { LinkList <int> list = new LinkList <int>(); bool empty = list.IsEmpty(); { int front = list.Front(); int back = list.Back(); Console.WriteLine("front:" + front + " back:" + back); } { list.PushBack(30000); int front = list.Front(); int back = list.Back(); Console.WriteLine("front:" + front + " back:" + back); } for (int i = 0; i < 6; ++i) { list.PushBack(i); Console.WriteLine("Size:" + list.Size()); } empty = list.IsEmpty(); list.PushFront(10); list.Traverse(); { int front = list.Front(); int back = list.Back(); Console.WriteLine("front:" + front + " back:" + back); } Swap(list, 5, 2); Swap(list, 0, 4); Swap(list, 5, 3); Swap(list, 0, 2); list.Delete(3, Compare); list.Traverse(); Console.WriteLine("Size:" + list.Size()); Console.WriteLine(); list.Delete(0, Compare); list.Traverse(); Console.WriteLine("Size:" + list.Size()); Console.WriteLine(); list.Delete(4, Compare); list.Traverse(); Console.WriteLine("Size:" + list.Size()); Console.WriteLine(); list.InsertSort(Compare); list.Traverse(); LinkListIterator <int> iterator = list.Begin(); while (iterator != list.End()) { Console.WriteLine(iterator.Element); iterator++; } }