c#数据结构(第一章)
集群
- 线性群集
- 非线性群集
线性群集
- 直接存取群集(数组,字符串,结构)ArrayList,StringBuild,Struct
- 顺序存取群集(栈,队列)Stack,Queue
- 索引群集(散列表,字典)Hashtable,Directionary
非线性群集
- 层次群集(树-二叉树,堆)
- 组群集(集合,图,网络)
通过CollectionBase类实现Collection类
View Code
class Collection:CollectionBase { public void Add(object item) { InnerList.Add(item); } public void Remove(object item) { InnerList.Remove(item); } public int Count(object item) { return InnerList.Count; } }
泛型编程
View Code
class Nodes<T> { T data; Nodes<T> Link; public Nodes(T data,Nodes<T> Link) { this.data = data; this.Link = Link; } } static void Swap<T>(ref T a, ref T b) { T temp; temp = a; a = b; b = temp; }
程序运行时间测试类
View Code
class Timing { TimeSpan duration; public Timing() { duration = new TimeSpan(0); } public void StopTime() { duration = Process.GetCurrentProcess().TotalProcessorTime; } public void StartTime() { GC.Collect(); GC.WaitForFullGCApproach(); } public TimeSpan Result() { return duration; } }
View Code
class Program { static void Main(string[] args) { int[] nums=new int[100000]; BuildArray(nums); TimeSpan duration; Timing t=new Timing(); t.StartTime(); DisplayNums(nums); t.StopTime(); Console.WriteLine("time:"+t.Result().TotalSeconds); Console.ReadKey(); } static void DisplayNums(int[] args) { int a = args.GetUpperBound(0); for (int i = 0; i < args.GetUpperBound(0); i++) { ; } } static void BuildArray(int[] args) { for (int i = 0; i <= 99999; i++) { args[i] = i; } } }