zoukankan      html  css  js  c++  java
  • c#数据结构(第一章)

    集群

    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;
                }
            }
    
        }
  • 相关阅读:
    C#中Excel的导入和导出的几种基本方式
    关于XML与类型Class的映射
    关于模板的相关注意事项
    OGRE 2.1 Windows 编译
    R6010 -abort() has been called
    VS2012 编译 Assimp
    C++ 并发消息队列
    Debian 安装下载工具软件
    Oracle SQL语句追踪
    记录自己学习网址
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/2771431.html
Copyright © 2011-2022 走看看