Cluster
- Linear Cluster
- Non-linear Cluster
Linear Cluster
- Direct access to the cluster (array, String, structure) arraylist, stringbuild, struct
- Sequential access cluster (stack, queue) stack, queue
- Index Cluster (hash, dictionary) hashtable, direary ary
Non-linear Cluster
- Hierarchical Cluster (tree-binary tree, heap)
- Group cluster (set, graph, Network)
Use the collectionbase class to implement the collection class
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; } }
Generic programming
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; }
Program running time test
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; } } }