c#中基本链表的实现
来源:互联网 发布:豆瓣fm 网络异常 编辑:程序博客网 时间:2024/06/05 12:18
1.基本链表的实现
功能:插入,删除,遍历显示
using System;using System.Collections;using System.Diagnostics.Eventing.Reader;using System.Security.Cryptography.X509Certificates;using System.Text;public class Node{ public Object item; //数据 public Node Link; //指针 public Node() { item = "header"; //创建节点s Link = null; } public Node(Object str) { item = str; //使用指定字符构建节点 Link = null; }}public class LinkList{ public Node header; //头结点 public LinkList() {//构造函数 header=new Node(); //构造头结点 } public void Insert(Object str, Object after) {//在某一节点后面插入节点 Node current = Find(after); //查找某一节点 if (current == null) { Console.WriteLine("没有找到前节点无法完成插入操作"); return; } Node newnode=new Node(str); newnode.Link = current.Link; //完成插入操作 current.Link = newnode; } private Node Find(Object str) {//查找某一节点 Node current = header; while(current!= null&¤t.item!=str) {//如果当前节点不为空s current = current.Link; } return current; //返回当前节点 } public void print() //打印所有节点 { Node current = header.Link; while(current != null) { Console.WriteLine(current.item); current = current.Link; } } public Node PreFind(Object str) {//查找这个节点的上一个节点 Node current = header; while (current.Link.item != str && current.Link!=null) {//如果不为空并且不为这个值 current = current.Link; } return current; } public void Remove(Object str) { Node current = PreFind(str); //查找这个节点的前一个节点 if (current.Link == null) { Console.WriteLine("没有找到这个要删除的节点"); return; } if (current.Link.Link != null) {//要删除节点的后面还有节点 current.Link = current.Link.Link; //这节连接 } else { current.Link = null; //否则直接断开连接 } }}public class Test{ public static void Main() { LinkList list=new LinkList(); list.Insert("jiajia1", "header"); list.Insert("jiajia2", "jiajia1"); list.Insert("jiajia3", "jiajia2"); list.Insert("jiajia4", "jiajia3"); list.Remove("jiajia4"); //删除节点 list.print(); }}
0 0
- c#中基本链表的实现
- c#中实现对数据库的基本操作
- c#中内置链表的基本使用
- c#中内置链表的基本使用
- C#实现的基本算法
- C#实现的基本算法
- 顺序表中基本操作的实现
- C#实现的基本算法 changqi [原作]
- C# 实现单链表的基本操作
- 算法的基本实现C#版
- C#实现队列的基本操作
- C#实现基本的矩阵数学库
- 链表的基本实现
- c#中简单链表的实现(非泛型)
- 图像处理中几个基本的处理方法c#代码实现
- C#中XML的基本操作
- C#中XML的基本操作
- C#中XML的基本应用
- 尝鲜系列之手把手教你汉化Ambari2.0.0
- 【miscellaneous】【ARM-Linux开发】ARM平台基于嵌入式Linux Gstreamer 使用
- windows下使用MinGW+msys编译ffmpeg
- 利用JavaCSV API来读写csv文件
- [生存志] 第58节 孔门十哲七十二贤
- c#中基本链表的实现
- 几种排序算法的实现与比较
- spring配置文件<import>标签中使用${}占位符获得配置文件的属性值
- 季度回望:月份总结:十一月总结,十二月展望
- 高德地图室内地图引入问题
- 第三十四将项目1-1+2+...+20 的总和
- uLua热更新学习笔记
- 简述dom中的事件流概念
- Python ImportError: cannot import name 'MongoClient'