【C#每日一记】常用泛型数据结构类及题单实践回顾

news2024/10/6 16:24:08

在这里插入图片描述


👨‍💻个人主页:@元宇宙-秩沅

👨‍💻 hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅!

👨‍💻 本文由 秩沅 原创

👨‍💻 收录于专栏unity之c#专题篇

在这里插入图片描述

🅰️



文章目录

    • 🅰️
    • 常用泛型数据结构类及题单实践回顾
    • 🎶(==A==)<font color=green >常用泛型数据结构类——List泛型类
    • 🎶(==B==)<font color=green >常用泛型数据结构类——Dictionary泛型类
    • 🎶(==C==)<font color=green >数据结构存储方式——顺序存储和链式存储
    • 🎶(==D==)<font color=green >常用泛型数据结构类——LinkedList泛型类
    • 🎶(==E==)<font color=green >常用泛型数据结构类——泛型栈和队列
    • 🎶(==F==)<font color=green >常用数据容器的不同应用情况
    • 🎶(==H==)实践——List类
    • 🎶(==J==)实践——Dictionary类
    • 🎶(==L==)实践——顺序存储和链式存储
    • 🎶(==M==)实践——LinkedList类
    • 🎶(==N==)实践
    • 🅰️


常用泛型数据结构类及题单实践回顾


🎶(A常用泛型数据结构类——List泛型类


在这里插入图片描述
在这里插入图片描述


🎶(B常用泛型数据结构类——Dictionary泛型类


在这里插入图片描述
在这里插入图片描述

  • hashtable的遍历 和 Dictionary 遍历API的区别对比
    +

🎶(C数据结构存储方式——顺序存储和链式存储


在这里插入图片描述
在这里插入图片描述


🎶(D常用泛型数据结构类——LinkedList泛型类


在这里插入图片描述
在这里插入图片描述


🎶(E常用泛型数据结构类——泛型栈和队列


  • 本质API和Stack类Queue类一样,加上了泛型
  • 并且前者再system.collection命名空间里
  • 后者在system.collection,Generic里

🎶(F常用数据容器的不同应用情况


总结数组,list,Dectionary,Stack,Queue,LinkedList等存储容器。我们怎么来使用

  • 数组:简单的数据类型存储的时候,或者只需要查改数据的时候

  • List:它是ArraryList的泛型升级,适合一切对象的存储,适合查改的情况下使用

  • LinkeList:它是泛型双向链表,适合频繁增删的数据对象的情况下使用
    在这里插入图片描述

  • Dectionary:它是Hashtable的泛型升级,适合键值对象的存储
    在这里插入图片描述

  • Stack:适合先进后出的情况下使用

  • Queue:适合先进先出的情况下使用
    在这里插入图片描述


🎶(H实践——List类


  • 实践经验

    1.构造函数中调用自身对象用this
    2.LIst的函数和ArrryList的函数基本一致
    3.List和ArraryList最大的区别就是前者的本质是泛型数组,后者的本质是Object数组
    4.继承的时候,子类默认先调用父类的构造函数

在这里插入图片描述

  /// <summary>
    /// 13.List的删除和存取
    /// </summary>
    //class Program
   // {
        //List和ArrayList的区别:前者结合了泛型,避免了拆箱装箱,效率更加优化
        //static void Main(string[] args)
        //{ 
        //    List<int> text = new List<int>();
        //    int[] arrary = new int[10]{ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
        //    int i = 0;
        //    while (i<arrary.Length)
        //    {
        //        text.Add(arrary[i++]);
        //    }
        //    text.RemoveAt(5);
        //    foreach (int item in text)
        //    {
        //        Console.WriteLine(item);
        //    }
        //}
    //}
         
    ///在构造函数中用List存取元素
    class Monster
    {
       static public  List<Monster> control = new List<Monster>();
       public Monster()
        {
            control.Add(this); 
        }
        virtual public void attack() { }
    }
    class Boss : Monster
    {
        public override void attack()
        {
            Console.WriteLine("放大招");
        }
    }
    class Gablin : Monster
    {
        public override void attack()
        {
            Console.WriteLine("哥布林的技能");
        }
    }
    class Program
    {
    static void Main(string[] args)
    {
            Boss boss1 = new Boss();
            Gablin boss2 = new Gablin();
            Monster text = new Monster();
            foreach (Monster  item in Monster .control )
            {
                item.attack();
            }
    }
 }

🎶(J实践——Dictionary类


  • 实践经验

    1.不能再foreach迭代器里面修改键值不然会报错
    2.只要存在从一个数据获得另一个数据就可以应用Dictionary
    在这里插入图片描述
private  Dictionary<int, string> text = new Dictionary<int, string>();
        public Program()
        {
            string[] upperArrary = { "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" };
            for (int i = 0; i < upperArrary.Length; i++)
            {
              text.Add(i + 1, upperArrary[i]);
            }
        }
        public void  Upper( string num  )
        {
            for (int i = 0; i < num.Length; i++)
            {
                int index = num[i] - '0';
                Console.Write(text[index]);
            }           
        }
        static void Main(string[] args)
        {
            Program Exam = new Program();
            Console.WriteLine(Exam.text[3]);
            try
            {           
                Console.WriteLine("请输入一个不超过三位数的整数");
                int num = int.Parse(Console.ReadLine());
                Exam.Upper(num.ToString());   
            }
            catch (Exception)
            {
                throw;
            }
        }

在这里插入图片描述

Dictionary<char, int> text = new Dictionary<char, int>();
      
        public void Multiplay(string arrray )
        {
            for (int i = 0; i < arrray.Length; i++)
            {
                if(text.ContainsKey(arrray[i]))
                {
                    text[arrray[i]] += 1;
                }
                else
                {
                    text.Add(arrray[i],1);
                }
            }
        }
       public  void Print()
        {
            foreach (KeyValuePair<char ,int> item in text)
            {
                Console.WriteLine(item);
            }
        }
        static void Main(string[] args)
        {
            Program text = new Program();
            string arrary = "Welcome to Unity World";
            string Arrary = arrary.ToUpper();         
            text.Multiplay(Arrary);
            text.Print();
        }

在这里插入图片描述


🎶(L实践——顺序存储和链式存储


  • 实践经验

    1.最大的应用区别在于顺序存储适合查改,链式存储适合增删
    2.构建链表时要考虑全面,考虑到每个节点相互之间的关系,看代码的逻辑性是否严谨
    在这里插入图片描述
 //1.
    //顺序存储是一组连续的存储单元依次存储在线性表中的存储 方式(连续存储)
    //链式存储是将一组任意不连续的存储单元存储在线性表中存储方式(任意存储)
    //2.
    //顺序存储的查改效率大于链式存储
    //链式存储的增删效率大于顺序存储
    //3.
    //常用的数据结构有:数组,链表,栈,队列,数,图,堆,散列表
 
    class LinkedNode<T>
    {   
        public T vaule;
        public LinkedNode(T Vaule)
        {
            this.vaule = Vaule;
        }
        public LinkedNode<T> peakLink = null;
        public LinkedNode<T> nextLink = null;
    }
    class Link<T>
    {
        private int count = 0;
        private LinkedNode<T> head;
        private LinkedNode<T> last;

        public int Count { get => count;  }
        public LinkedNode<T> Peak { get => head; }
        public LinkedNode<T> Last { get => last; }

        public void Add(LinkedNode<T> node) //添加节点
        {
            if (head == null)
            {
                head = node;
                last = node;
                count++;
            }
            else
            {
                //尾插法        
                LinkedNode<T> temp = last; ;
                last.nextLink = node;          
                last = node;
                last.peakLink = temp;
                count++;
            }
        }

        public void RemoveAt(int index) //删除节点
        {
            LinkedNode<T> Lnode = head ;
          
            int temp = 1;
            if (index > count || index < 1)
            {
                Console.WriteLine("超出链表规定范围,请输入正确范围进行移除操作!");
                return;
            }
            else if (index == 1)
            {
                Console.WriteLine("指令为删除头节点");
                head = head.nextLink;
            }
            else if (index == count)
            {
                Console.WriteLine("指令为删除尾节点");
                
                last = last.peakLink;
                Console.WriteLine("此时尾节点为:" + last.vaule);
                last.nextLink = null;
              
            }
            else
            {
                while (true)
                {
                    if (temp == index)
                    {
                        if (Lnode.peakLink != null)
                            Lnode.peakLink.nextLink = Lnode.nextLink;
                        if (Lnode.nextLink != null)
                            Lnode.nextLink.peakLink = Lnode.peakLink;
                        break;
                    }
                    temp++;
                    count--;
                    Lnode = Lnode.nextLink;
                }
            }
        }

        public void Print() //遍历所有节点
        {
            LinkedNode<T> Lnode = head;
            
            while(Lnode != null )
            {
                Console.WriteLine("节点的值为:"+Lnode.vaule );
                Lnode = Lnode.nextLink;
            }

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Program text = new Program();
            LinkedNode<int> node1 = new LinkedNode<int>(1);
            LinkedNode<int> node2 = new LinkedNode<int>(2);
            LinkedNode<int> node3 = new LinkedNode<int>(3);
            Link<int> list = new Link<int>();
            list.Add(node1);
            list.Add(node2);
            list.Add(node3);
            Console.WriteLine("此时链表的长度为:" + list.Count);
            list.RemoveAt(2);
            list.Print();
        }       
    }

🎶(M实践——LinkedList类


  • 实践经验

    1.本质上就是泛型的双向链表
    2.当需要进行节点操作的时候,才用到节点类的API
    3.所以需要掌握LinkedList 和LinkedListNode两个类

    在这里插入图片描述

            LinkedList<int> list = new LinkedList<int>();
            Random rand = new Random();
            int temp = 10;
            while(temp-->=1)
            {
                list.AddFirst(rand.Next(101));
            }
            //foreach遍历
            //foreach (var item in list)
            //{
            //    Console.WriteLine(item);
            //}
            LinkedListNode<int> node = list.First;
            //节点遍历——头节点遍历
            Console.WriteLine("从头部开始 遍历了");
            while(node!= null )
            {
                Console.WriteLine(node.Value);
                node = node.Next;
            }
            //节点遍历 ——尾节点遍历\
            Console.WriteLine("从尾部开始 遍历了");
            node = list.Last;
            while (node != null)
            {
                Console.WriteLine(node.Value);
                node = node.Previous ;
            }

🎶(N实践


总结数组,list,Dectionary,Stack,Queue,LinkedList等存储容器。我们怎么来使用

  • 数组:简单的数据类型存储的时候,或者只需要查改数据的时候
  • List:它是ArraryList的泛型升级,适合一切对象的存储
  • LinkeList:它是泛型双向链表,适合频繁增删的数据对象的情况下使用
  • Dectionary:它是Hashtable的泛型升级,适合键值对象的存储
  • Stack:适合先进后出的情况下使用
  • Queue:适合先进先出的情况下使用

🅰️


⭐【Unityc#专题篇】之c#进阶篇】

⭐【Unityc#专题篇】之c#核心篇】

⭐【Unityc#专题篇】之c#基础篇】

⭐【Unity-c#专题篇】之c#入门篇】

【Unityc#专题篇】—进阶章题单实践练习

⭐【Unityc#专题篇】—基础章题单实践练习

【Unityc#专题篇】—核心章题单实践练习


你们的点赞👍 收藏⭐ 留言📝 关注✅是我持续创作,输出优质内容的最大动力!


在这里插入图片描述


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/952262.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【算法题】1761. 一个图中连通三元组的最小度数

题目&#xff1a; 给你一个无向图&#xff0c;整数 n 表示图中节点的数目&#xff0c;edges 数组表示图中的边&#xff0c;其中 edges[i] [ui, vi] &#xff0c;表示 ui 和 vi 之间有一条无向边。 一个 连通三元组 指的是 三个 节点组成的集合且这三个点之间 两两 有边。 连…

Java流式编程详细介绍

文章目录 1. 流式编程介绍2. 过滤2.1 filter2.2 distinct2.3 limit2.4 sorted2.5 skip 3. 映射3.1 map3.2 flatmap 4 查找4.1 allMatch4.2 anyMatch4.3 noneMatch4.4 findFirst4.5 findAny 5. 归约6. 收集6.1 counting6.2 maxBy,minBy6.3 summingInt、summingLong、summingDoub…

zookeeper 3.8.1安装和入门使用

1、zookeeper环境搭建&#xff08;Windows单机版&#xff09; 1.1、 前提 必须安装jdk 1.8&#xff0c;配置jdk环境变量&#xff0c;步骤略 1.2、安装zookeeper 地址&#xff1a;https://zookeeper.apache.org/ 1.2.1、选择releases版本 1.2.2、下载安装包并解压 1.2.3、配…

大厂面试解码:如何准备Google, Amazon等公司的面试

&#x1f337;&#x1f341; 博主猫头虎 带您 Go to New World.✨&#x1f341; &#x1f984; 博客首页——猫头虎的博客&#x1f390; &#x1f433;《面试题大全专栏》 文章图文并茂&#x1f995;生动形象&#x1f996;简单易学&#xff01;欢迎大家来踩踩~&#x1f33a; &a…

Spring Session中会将会话ID记录到标准输出流中危漏洞CVE-2023-20866

文章目录 0.前言漏洞受影响的Spring产品和版本 1.参考文档2.基础介绍描述 3.解决方案3.1. 升级版本 4.HeaderHttpSessionIdResolver 解析5. Spring Session 使用教程 0.前言 背景&#xff1a;公司项目扫描到 CVE-2023-20866&#xff1a;在Spring Session中会将会话ID记录到标准…

WevSocket(java基于spring框架实现)

一、概述 本文基于spring-boot-starter-websocket简单的完成收发信息功能&#xff0c;使用spring框架进行实现。 二、相关配置 spring:2.0.2&#xff0c;jdk:1.8.202&#xff0c;maven:3.3.9 因为spring和maven有版本匹配的要求&#xff0c;请大家注意自己的版本是否匹配 …

专线连接交换机设置 – 如何实现高效率的网络连接?

专线链接交换机设置 – 如何实现高效率的网络连接&#xff1f; 什么是专线连接交换机&#xff1f; 在现代互联网中&#xff0c;网络连接的快速和高效是至关重要的。尤其是对于需要大量数据传输和保证网络稳定性的企业和组织来说&#xff0c;专线连接交换机是一项非常重要的技…

华为云Stack的学习(四)

五、Service OM资源管理 1.Service OM简介 1.1 Service OM介绍 在华为云Stack解决方案中&#xff0c;Service OM是FusionSphere OpenStack的操作管理界面&#xff0c;是资源池&#xff08;计算、存储、网络&#xff09;以及基础云服务的管理工具。 1.2 Service OM定位 Serv…

分类算法系列②:KNN算法

目录 KNN算法 1、简介 2、原理分析 数学原理 相关公式及其过程分析 距离度量 k值选择 分类决策规则 3、API 4、⭐案例实践 4.1、分析 4.2、代码 5、K-近邻算法总结 &#x1f343;作者介绍&#xff1a;准大三网络工程专业在读&#xff0c;努力学习Java&#xff0c;涉…

Vue-关于路由规则模块的封装

路由的封装抽离 对路由的封装进行封装&#xff0c;方便main.js文件维护 首先&#xff1a; 我们需要再src文件夹中创建一个router文件夹&#xff0c;在里面在创建一个index.js文件夹。 然后&#xff1a; 我们再index.js文件夹中进行封装路由规则 import Find from /views/F…

技术深入解析与教程:网络安全技术探秘

第一章&#xff1a;引言 在当今数字化时代&#xff0c;网络安全已经成为了重要议题。随着各种信息和业务在网络上的传输与存储&#xff0c;安全问题也日益突出。本文将带您深入探讨网络安全领域中的关键技术&#xff0c;涵盖渗透测试、漏洞挖掘以及恶意软件分析等方面&#xf…

opencv android sdk 使用中的问题

Plugin with id ‘kotlin-android’ not found 在build.gradle(:app)中添加以下内容 buildscript {ext {Kotlin_Verion "1.9.10"}dependencies {classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$Kotlin_Verion"}repositories {mavenCentral()} …

SpringBoot通过@Cacheable注解实现缓存功能

目录 一、Spring从3.1开始支持Cache二、Cacheable常用属性1、value/cacheNames2、key3、condition4、unless5、keyGenerator6、sync7、cacheManager 三、整合步骤1、加入pom2、启动类加EnableCaching注解3、controller或service加Cacheable注解即可 四、代码实例五、Spring Boo…

Linux下批量创建文件夹

检测文件是否存在 这里的文件包含普通文件或者是目录文件,下面是CentOS 7环境下的测试. #include <sys/stat.h> #include <unistd.h> #include <iostream>int main() {int ret access("../lesson01/file.txt", F_OK);if (ret 0){std::cout <…

经管博士科研基础【6】:如何理解箱式图

箱形图,也叫盒须图,盒式图,boxplot。有95%的把握猜中你现在已经不太确定,这图中有几条线?每条线代表什么意思?中间的那条线代表的究竟是算数平均数还是中位数,还是众数? 再问的深点,箱形图存在的意义为何?之于数据分析的实践意义在哪里? 接下来,带你从概念开始,…

如何回答‘行为面试题’:用实例展示你的能力

&#x1f337;&#x1f341; 博主猫头虎 带您 Go to New World.✨&#x1f341; &#x1f984; 博客首页——猫头虎的博客&#x1f390; &#x1f433;《面试题大全专栏》 文章图文并茂&#x1f995;生动形象&#x1f996;简单易学&#xff01;欢迎大家来踩踩~&#x1f33a; &a…

Linux 8 下的容器引擎Podman概述

一、前言 最近在进行OS国产化交流中&#xff0c;了解到部分业务迁移到BClinux 8.2或Anolis 8.2时&#xff0c;原有docker业务需要迁移到新的容器平台&#xff1a;Podman&#xff0c;来完成容器的新的管理。Podman&#xff08;全称 Pod Manager&#xff09;是一款用于在 Linux 系…

MOS管的损耗分析

目的 1、MOS管的损耗分类&#xff1a; 开关损耗&#xff1a; 栅驱动损耗&#xff1a; 导通损耗&#xff1a; 主要内容 MOS管损耗主要有开关损耗&#xff08;开通损耗和关断损耗&#xff0c;关注参数Cgd(Crss)&#xff09;、栅极驱动损耗&#xff08;关注参数Qg&#xff09;和…

面试流程解析:从初面到终面,程序员需要注意什么

&#x1f337;&#x1f341; 博主猫头虎 带您 Go to New World.✨&#x1f341; &#x1f984; 博客首页——猫头虎的博客&#x1f390; &#x1f433;《面试题大全专栏》 文章图文并茂&#x1f995;生动形象&#x1f996;简单易学&#xff01;欢迎大家来踩踩~&#x1f33a; &a…

RabbitMQ 的快速使用

docker部署rabbitmq # management才有管理页面 docker pull rabbitmq:management# 新建容器并运行 docker run \-e RABBITMQ_DEFAULT_USERadmin \ -e RABBITMQ_DEFAULT_PASSadmin \ -v mq-plugins:/plugins \--name mq \--hostname mq \-p 15672:15672 \-p 5672:5672 \-itd \ra…