03-数据结构(一)

链接:C# 数据结构_哔哩哔哩_bilibili

https://www.bilibili.com/video/BV1a541147Nk/?spm_id_from=333.337.search-card.all.click&vd_source=6eb7d966aa03ff5cb02b63725f651e68

链接:使用 C#.Net 学习掌握数据结构 (更新中)_哔哩哔哩_bilibili

一个:

C#编程-第五季-数据结构和算法-宇宙最简单教程_哔哩哔哩_bilibili

C#编程-第六季-编程内功修炼-算法-宇宙最简单教程_哔哩哔哩_bilibili

一、数据结构

基础语法、  数据结构与算法、网络编程与多线程、网络通信、队列、WPF基础、Winform基础、数据库基础、容器、docker、prism框架。  WebApi。

RemoveAt:根据索引移除

1、列表

1.1、线性表

顺序表的存储:顺序表中的每个元素占w个存储单元,设第i个数据元素的存储地址为Local(ai)则有:Local(ai)=Local(a1)+(i-1)*w。也是顺序表的起始地址,顺序表的基地址,顺序表任意存取的特点,占用的是一组连续的存储空间,具有任意存取的特点,数组具有天生表示顺序表的数据存储区域的特性。

在这个例子中,索引器允许你通过索引来读取(get)和写入(setSeqList<T>中的元素。如果SeqList<T>没有索引器,并且你试图像数组一样使用它(即mySeqList[index]),编译器会报错,因为它不知道如何处理这样的语法。

因此,如果你在使用自定义集合类(如SeqList<T>)时遇到索引相关的错误,很可能是因为该类没有实现索引器,或者你尝试访问的索引超出了集合的有效范围。确保你的类正确实现了索引器,并在使用索引器时始终检查索引的有效性,以避免IndexOutOfRangeException异常。

代码:

  interface IList1<T>{int GetLength();void Clear();bool IsEmpty();void Add(T item);void Insert(T item, int index);T Delete(int index);//T this[int index] { get; }T GetEle(int index);int Locate(T value);}
 internal class SeqList<T> : IList1<T>{///  顺序表实现方式public T[] data;  //  存储数据public int count = 0;  //  表示存了多少个数据public SeqList(int size)   //  size最大容量{data = new T[size];}public SeqList() : this(10)  //  默认构造函数容量是10{}public T this[int index]{get { return GetEle(index); }}public void Add(T item){if (count == data.Length){Console.WriteLine("当前数组已存满,不允许再存");}else{data[count] = item;count++;}}public void Clear(){throw new NotImplementedException();}public T Delete(int index){T item = data[index];for(int i = index - 1; i < count - 1; i++){data[i] = data[i + 1];}count--;return item;}public T GetEle(int index){if (index >= 0 && index <= count - 1){return data[index];}else{Console.WriteLine("索引不存在");return default(T);  }}//  取得数据的长度public int GetLength(){return data.Length;}public void Insert(T item, int index){for(int i=count-1; i>=index; i--){data[i] = data[i-1];}}public bool IsEmpty(){throw new NotImplementedException();}public int Locate(T value){for (int i = 0; i < count-1; i++){if (data[i].Equals(value)){return i;}}return -1;  /// 表示值不存在;}}

2、链表

单链表和双链表:

2.1、单链表

单链表使用地址连续的存储单元顺序存储线性表中的各个数据元素,链式存储,链表不要求逻辑上相邻的数据元素在物理存储位置上页相邻,因此,在对链表进行插入和删除时不需要移动数据元素,但是同时页失去了顺序表可随机存储的有带你。

表头  数据  下一个数据的地址

    internal class Node1<T>{private T data;  //  存储元素private Node1<T> next;   // 用来指向下一个元素public Node1(T value){data = value;next = null;}public Node1(T value, Node1<T> next){this.data = value;this.next = next;}public Node1(){data=default(T);next= null;}public  Node1(Node1<T> next){this.next = next;}public T Data{get { return data; }set {  data = value; }}public Node1<T> Next{get { return next; }set { next = value; }}}

代码:

   interface IList1<T>{int GetLength();void Clear();bool IsEmpty();void Add(T item);void Insert(T item, int index);T Delete(int index);//T this[int index] { get; }T GetEle(int index);int Locate(T value);}
  internal class linkList<T> : IList1<T>{public Node1<T> head;   // 第一个节点public linkList() {head = null;}public void Add(T item){Node1<T> newNode = new Node1<T>(item);  //  根据新的数据创建新的节点if (head == null){head = newNode;}else{Node1<T> temp = head;while (true){if (temp.Next != null){temp = temp.Next;}else{break;}}temp.Next = newNode;}}public void Clear(){throw new NotImplementedException();}public T Delete(int index){T data;if (index == 0){data = head.Data;head = head.Next;return data;}else{Node1<T> temp = head;for (int i = 0; i < index; i++){temp = temp.Next;}data = temp.Next.Data;temp.Next = temp.Next.Next;return data;}}public T GetEle(int index){throw new NotImplementedException();}public int GetLength(){if(head==null) return 0;Node1<T> temp = head;int count = 1;while(temp != null){if(temp.Next != null){count++;temp= temp.Next;}else{break;}}return count;}public void Insert(T item, int index){Node1<T> newNode=new Node1<T>(item);if(index==0){newNode.Next = head;head= newNode;}else{Node1<T> temp=head;for (int i=0; i<index; i++){temp = temp.Next;}newNode.Next = temp.Next;temp.Next = newNode;}}public bool IsEmpty(){throw new NotImplementedException();}public int Locate(T value){Node1<T> temp = head;if (temp == null){return -1;}else{int index = 0;while (true){if (temp.Data.Equals(value)){return index;}else{if(temp.Next!= null){index++;temp = temp.Next;}else{break;}}}return -1;}}}

2.2、双链表

指向前一个节点,先进后除,,没有计数,

3、栈

3.1、顺序栈(Stack)

是操作元素限定在表的尾端进行的线性表,表尾由于要进行插入、删除等操作,所以,它具有特殊的含义,把表尾称为栈顶(Top)另一端固定,叫做栈底,当为空,脚空栈。

栈通常记为:S=(a1, a2, ...,an) a1为栈底元素,an为栈顶元素。a1到an依次入栈,出栈则次序相反,an第一个出栈,a1最后出栈。栈的操作是按照后进先出或现金后出的原则进行

 SeqList<string> strList = new SeqList<string>();strList.Add("123");strList.Add("456");strList.Add("789");Console.WriteLine("123456789");Console.WriteLine(strList[0]);Console.ReadLine();Console.WriteLine(strList);Console.WriteLine(strList.GetLength());for (int i = 0; i < strList.GetLength(); i++){Console.WriteLine(strList[i]);}Console.ReadLine();Stack<string> stack = new Stack<string>();stack.Push("a");stack.Push("b");stack.Push("c");Console.WriteLine(stack.Pop());Console.ReadLine();

代码:  类似于数组,用数组构造栈的先进后出

    interface IsStackDS<T>{int Count { get; }int GetLength();bool IsEmpty();void Clear();void Push(T item);T Pop();T Peek();}
    internal class seqStack<T> : IsStackDS<T>{private T[] data;private int top;public seqStack(int size){data = new T[size];top = -1;}public int Count { get { return top+1; } }public void Clear(){top=-1;}public int GetLength(){return Count;}public bool IsEmpty(){return Count==0;}public T Peek(){throw new NotImplementedException();}public T Pop(){T temp = data[top];top--;return temp;}public void Push(T item){data[top+1]=item;top++;}}

3.2、链栈

栈顶Top   为Node1 类  出栈时候指向下一个Node1

其他和单链表类似:

代码: 但是用链表的形式描述栈的先进后出,需要用到类节点   Node

    internal class linkStack<T> : IsStackDS<T>{private T data;private Node1<T> top;private int count;//public seqStack(int size)//{//    data = ;//    top = null;//}public int Count { get { return count; } }public void Clear(){top = null;count = 0;}public int GetLength(){return Count;}public bool IsEmpty(){return Count == 0;}public T Peek(){throw new NotImplementedException();}public T Pop(){data = top.Data;top=top.Next;count--;return data;}public void Push(T item){Node1<T> newNode = new Node1<T>(item);newNode = new Node1<T>(item);top.Next = top;top = newNode;count++;}

4、队列

代码:队头  队尾  ,先进先出,front 先出,有计数:count。

4.1、顺序队列

用以连片的存储空间老存储队列中的数据元素,这样的队列称为顺序队列(Sequence   Queue)。类似于顺序栈,

代码:需要设置数组的大小

    interface IsQueueDS<T>{int Count {  get; }int GetLength();bool IsEmpty();void Clear();void Enqueue(T item);T Dequeue();T Peek();}
  internal class seqQueue<T> : IsQueueDS<T>{private T[] data;private int count;private int front;  //  队首,从  -1 开始private int rear;  //  队尾public seqQueue(int size){data=new T[size];count = 0;front = -1;rear = -1;}public int Count { get { return count; } }public void Clear(){count=0;}public T Dequeue(){if (count >0){T temp = data[front + 1];front++;count--;return temp;}else{Console.WriteLine("无法取得,队列为空");return default(T);}}public void Enqueue(T item){if (count == data.Length){Console.WriteLine("队列已经满了");}else{if(rear==data.Length-1)  //  判断是否在末尾,从头开始{data[0]=item;rear = 0;}else{data[rear + 1] = item;rear++;}}}public int GetLength(){return count;}public bool IsEmpty(){return count == 0 ;}public T Peek(){T temp=data[front+1];return temp;}}

4.2、链队列

表与链,  栈与队列,不需要设置数组的大小

 internal class Node1<T>{private T data;  //  存储元素private Node1<T> next;   // 用来指向下一个元素public Node1(T value){data = value;next = null;}public Node1(T value, Node1<T> next){this.data = value;this.next = next;}public Node1(){data=default(T);next= null;}public  Node1(Node1<T> next){this.next = next;}public T Data{get { return data; }set {  data = value; }}public Node1<T> Next{get { return next; }set { next = value; }}}

代码:

    interface IsQueueDS<T>{int Count {  get; }int GetLength();bool IsEmpty();void Clear();void Enqueue(T item);T Dequeue();T Peek();}
    internal class linkQueue<T> : IsQueueDS<T>{private Node1<T> front;private Node1<T> rear;private T data;private int count;public linkQueue(){front = null;rear = null;count = 0;}public int Count {  get { return count; } }public void Clear(){front = null;rear = null ;count = 0;}public T Dequeue(){if (count == 0){Console.WriteLine("为空无法出队列");return default(T);}else if(count == 1){T temp = front.Data;front = null;rear = null;count = 0;return temp;}else{T temp = front.Data;temp=front.Data;front=front.Next;count--;return temp;}}public void Enqueue(T item){Node1<T> newNode = new Node1<T>(item);if (count == 0){front = newNode;count = 1;rear= newNode;}else{rear.Next = newNode;rear = newNode;count++;}}public int GetLength(){return count;}public bool IsEmpty(){return count == 0 ;}public T Peek(){return front.Data;}}

5、字符串

字符串类的创建

6、数组

数组的创建:



7、算法

算法:

7.1、快速排序

作为排序依据的数据项称为  ”排序项“,也成为记录的  ”关键码“,关键码分为主关键码和次关键码。一般地,若关键码是主关键码,则对于任意排序的序列,经排序后得到的结果是唯一的;弱为次关键码,排序结果不唯一,这是因为待排序的序列中可能存在具有相同关键码的记录。此时,这些记录在排序结果中,他们之间的位置关系与排序前不一定保持一致。如果使用某个排序方法对任意的记录序列关键码进行排序,形同关键码值得记录之间得位置关系与排序前一致,则称此排序方法是稳定的,如果不一致,则称此排序方法是不稳定的。

由于待排序得记录得数量不同,使得排序过程中设计得存储器不同,可将排序方法分为内部排序和外部排序两大类。

内部排序值得是在排序过程中,记录全部存放在计算机得内存中,并在内存中调整记录之间得相对位置,在此期间没有进行内、外存的数据交换。外部排序指的是在排序过程中,记录得主要部分存放在外存中,借助于内存逐步调整记录之间得相对位置。在这个过程中,需要不断地在内外存之间交换数据。

排序:排序项,

快速排序:

7.1.1、直接插入排序

双重循环,逐个比较排序,直接拿后一个与前边所有去比较

7.1.2、冒泡排序

将相邻得记录得关键码进行比较,若前边记录的关键码大于后边记录的关键码,则将它们交换,否则不交换。需要操作N-1次,,N为元素个数。

7.1.3、简单选择排序

先将第一个作为比较直,与后边得所有元素中得最小值比较,然后交换位置。

7.1.4、快速排序

先取得一个基数,即0位置,,然后从后索引找到比它小的,再从前往后找比它小的。

直到基数放在某个位置使得将数组分为两个部分。前边都比基数小,后边都比基数大。

internal class Program
{static void QuickSort(int[] dataArray,int left,int right){if(left<right){int x = dataArray[left];int i = left;int j = right;while(true&&i<j){while (true && i < j){if (dataArray[j] <= x){dataArray[i] = dataArray[j];break;}else{j--;}}while (true && i < j){if ((dataArray[i] >x)){dataArray[j] = dataArray[i];break;}else{i++;}}}//  此时i==j找到中间位置dataArray[i] = x;QuickSort(dataArray,left,i-1);QuickSort(dataArray,i+1,right);}}static void Main(string[] args){int[] data = new int[] { 42, 20, 17, 27, 13, 8, 17, 48 };QuickSort(data,0,data.Length-1);foreach(var temp in data){Console.WriteLine(temp);}}

7.1、二叉树

算法、重点

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

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《Python编程从入门到实践》day28

# 昨日知识点回顾 安装Matplotlib 绘制简单的折线图 # 今日知识点学习 15.2.1 修改标签文字和线条粗细 # module backend_interagg has no attribute FigureCanvas. Did you mean: FigureCanvasAgg? # 解决办法&#xff1a;matplotlib切换图形界面显示终端TkAgg。 #…

.NET 一款团队内部免杀的WebShell

01本文概要 在.NET应用程序中&#xff0c;有时需要执行一些与系统相关的操作&#xff0c;例如调用Windows API函数来实现特定功能。本示例展示了如何在.NET页面中调用名为zipfldr.dll的动态链接库DLL中的RouteTheCall函数。 02函数及代码示例 zipfldr.dll是Windows操作系统中…

每日一题12:Pandas:数据重塑-融合

一、每日一题 解答&#xff1a; import pandas as pddef meltTable(report: pd.DataFrame) -> pd.DataFrame:reshaped_report report.melt(id_varsproduct, var_namequarter, value_namesales)return reshaped_report 题源&#xff1a;Leetcode 二、总结 melt()函数是Pa…

ctfshow parse_url wp

第一关 这个parse_url函数就是解析URL并且进行拆分的 $url "https://www.example.com/path/to/page?param1value1&param2value2";$parsed_url parse_url($url);print_r($parsed_url); Array ([scheme] > https[host] > www.example.com[path] > /p…

智慧安防系统:构建更安全的社区环境

随着科技的不断进步&#xff0c;人们的生活质量得到了显著提高。然而&#xff0c;与此同时&#xff0c;社会治安问题也日益凸显。为了维护社会的和谐稳定&#xff0c;提高人们的生活安全感&#xff0c;智慧安防系统应运而生。本文将为您详细介绍智慧安防系统的项目背景、需求分…

第十六节:图 (20节)

一 图的概念 1&#xff09;由点的集合和边的集合构成 2&#xff09;虽然存在有向图和无向图的概念&#xff0c;但实际上都可以用有向图来表达 3&#xff09;边上可能带有权值 二 图结构的表达 1&#xff09;邻接表法 2&#xff09;邻接矩阵法 3&#xff09;除此之外还有其他众多…

【Mac】如何解决打开PD虚拟机后Mac无法上网的问题?

问题描述 部分用户在运行Parallels Desktop并打开Windows 11后&#xff0c;发现Windows上网没有问题&#xff0c;但是Mac主机不能访问带域名的网站&#xff0c;而访问带IP的网站没问题&#xff0c;退出Parallels虚拟机以后&#xff0c;Mac网络又恢复正常。 解决办法 退出 Pa…

DC-DC直流升压线性可调电源模块电压控制输出0-50V/0-80V/0-100V/0-200V/0-250V/0-300V/0-500V/0-1000V

特点 效率高达 75%以上1*2英寸标准封装单电压输出可直接焊在PCB 上工作温度: -40℃~75℃阻燃封装&#xff0c;满足UL94-V0 要求温度特性好电压控制输出,输出电压随控制电压线性变化 应用 GRB 系列模块电源是一种DC-DC升压变换器。该模块电源的输入电压分为&#xff1a;4.5~9V、…

通配符SSL证书免费领取!不限量!

通配符SSL证书&#xff08;泛域名证书&#xff09;可以为主域名及其所有子域名提供安全保护&#xff0c;而无需为每个子域名单独申请证书。这对于拥有多个子域名的网站来说&#xff0c;极大地简化了管理和部署SSL证书的过程。 对于学习、测试或者前期预算不足的用户来说&#…

酷开科技依托酷开系统“硬件+内容”产业布局,抢占全球机遇!

2024年3月26日&#xff0c;创维集团发布了2023年年度业绩报告&#xff0c;去年全年实现了总营业额690.31亿元较上一年的534.91亿元整体营业额增长了29.1%。然而&#xff0c;值得注意的是&#xff0c;2023年度&#xff0c;创维集团智能家电业务的营收306.37亿元&#xff0c;较上…

Python轻量级Web框架Flask(14)—— 自己做Flask项目总结

0、前言&#xff1a; 本文意在记录自己在做毕业Flask项目开发时遇到的一些问题&#xff0c;并将问题解决方案记录下来&#xff0c;可做日后查询本文也会记录自己做FLask项目时实现的一些功能&#xff0c;作为开发工作的进程记录注意&#xff1a;用Flask开发的前提是已经设计好…

【js逆向】易车网JS逆向案例实战手把手教学(附完整代码)

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全…

Flask Web开发:使用render_template渲染动态HTML模板

文章目录 Flask简介render_template函数参数说明示例代码 模板文件结果展示 在Web开发中&#xff0c;经常需要将动态数据与HTML模板结合&#xff0c;以生成具有用户特定信息的网页。Python的Flask框架提供了一个功能强大的 render_template函数&#xff0c;用于实现这一目标。…

只用了三天就入门了Vue3?

"真的我学Vue3&#xff0c;只是为了完成JAVA课设" 环境配置 使用Vue3要去先下载Node.js。 就像用Python离不开pip包管理器一样。 Node.js — Run JavaScript Everywhere (nodejs.org) 下完Node.js去学习怎么使用npm包管理器&#xff0c;放心你只需要学一些基础的…

【opencv】opencv透视变换和ocr识别实验

实验环境&#xff1a;anaconda、jupyter notebook 实验用到的包opencv、numpy、matplotlib、tesseract 一、opencv透视变换 原图 图片是我拍的耳机说明书&#xff0c;哈哈哈哈&#xff0c;你也可以使用自己拍的照片&#xff0c;最好是英文内容&#xff0c;tesseract默认识别英…

洛谷 P3372:线段树 1 ← 分块算法模板(区间更新、区间查询)

【题目来源】https://www.luogu.com.cn/problem/P3372【题目描述】 如题&#xff0c;已知一个数列&#xff0c;你需要进行下面两种操作&#xff1a; &#xff08;1&#xff09;将某区间每一个数加上 k。 &#xff08;2&#xff09;求出某区间每一个数的和。【输入格式】 第一行…

JavaScript进阶——05-迭代器和生成器【万字长文,感谢支持】

迭代器 概念 迭代器&#xff08;Iterator&#xff09;是 JavaScript 中一种特殊的对象&#xff0c;它提供了一种统一的、通用的方式遍历个各种不同类型的数据结构。可以遍历的数据结构包括&#xff1a;数组、字符串、Set、Map 等可迭代对象。我们也可以自定义实现迭代器&…

Python爬虫——如何使用urllib的HTTP基本库

怎样通过 urllib库 发送 HTTP 请求&#xff1f; urllib库主要由四个模块组成: urllib.request 打开和读取 URLurllib.error 包含 urllib.request 抛出的异常urllib.parse 用于解析 URLurllib.robotparser 用于解析 robots.txt 文件 1. 使用urllib.parse解析URL 使用urlparse(…

Linux连接文件那点事

什么是连接文件 将一个文件和另一个文件建立联系&#xff0c;分为硬链接和软连接&#xff08;符号连接&#xff09;。 硬链接 Linux中&#xff0c;所有的文件都有一个inode&#xff0c;这个东西就是文件的ID号&#xff0c;硬链接的方式就是通过这个inode来产生新的文件名来建…

【动态规划】:路径问题_地下城游戏

朋友们、伙计们&#xff0c;我们又见面了&#xff0c;本专栏是关于各种算法的解析&#xff0c;如果看完之后对你有一定的启发&#xff0c;那么请留下你的三连&#xff0c;祝大家心想事成&#xff01; C 语 言 专 栏&#xff1a;C语言&#xff1a;从入门到精通 数据结构专栏&…