c#資料結構(第一章)

來源:互聯網
上載者:User

叢集

  1. 線性群集
  2. 非線性群集

線性群集

  • 直接存取群集(數組,字串,結構)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;            }        }    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.