C # data structure (Chapter 1)

Source: Internet
Author: User

Cluster

  1. Linear Cluster
  2. 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;            }        }    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.