- 浏览: 531559 次
- 性别:
- 来自: 天津
文章分类
- 全部博客 (230)
- java (87)
- c/c++/c# (39)
- ASP.net MVC (4)
- eclipse/visual studio (3)
- tomcat/weblogic/jetty (13)
- linux/unix/windows (20)
- html/javascript/jquery/kendo/bootstrap/layui/vue/react (31)
- hibernate/struts/spring/mybatis/springboot (21)
- lucene/solr/ELK (2)
- shiro (0)
- oracle/sqlserver/mysql/postgresql (23)
- shell/python/ruby (6)
- android (0)
- maven/ant (1)
- freemarker/thymeleaf/velocity (1)
- open source project (41)
- cache/memcached/redis (0)
- nosql/hadoop/hbase/mongodb (0)
- system architecture/dubbo/zookeeper (0)
- software testing (0)
- system optimization (0)
- system security (0)
- tcp/udp/http (2)
- roller/wordpress (2)
- 工具收藏 (8)
- 文摘 (4)
- 生活 (0)
最新评论
-
coconut_zhang:
这个demo 非常完整了,是指下面说的那个html 模版,模版 ...
flying sauser, thymeleaf实现PDF文件下载 -
a93456:
你好,你有完整的demo吗? String template这 ...
flying sauser, thymeleaf实现PDF文件下载 -
yujiaao:
fn 函数循环是没有必要的啊,可以改成
protecte ...
Java 笛卡尔积算法的简单实现 -
安静听歌:
设置了.setUseTemporaryFileDuringWr ...
使用jxl导出大数据量EXCEL时内存溢出的解决办法 -
q280499693:
写的很详细,但是我现在想知道他们是怎么定位log4j.prop ...
关于SLF4J结合Log4j使用时日志输出与指定的log4j.properties不同
在结点中设两个引用域,一个保存直接前驱结点的地址,叫prev,一个直接后继结点的地址,叫next,这样的链表就是双向链表(Doubly Linked List)。
双向链表的结点结构示意图如上,双向链表结点的定义与单链表的结点的定义很相似,因此,双向链表节点类的实现可以参考单链表的节点类。
C#实现:
1接口
引用线性表的接口IListDS<T>
2实现
(1)双向链表节点类,参考单链表的节点类
public class DBNode<T>
{
private T data; //数据域
private DBNode<T> next; //后继
private DBNode<T> prev; //前驱
public T Data
{
get { return data; }
set { data = value; }
}
public DBNode<T> Next
{
get { return next; }
set { next = value; }
}
public DBNode<T> Prev
{
get { return prev; }
set { prev = value; }
}
public DBNode()
{
data = default(T);
prev = null;
next = null;
}
public DBNode(T val)
{
data = val;
next = null;
prev = null;
}
}
(2) 双向链表操作类实现
注意:由于双向链表的结点有两个引用,所以,在双向链表中插入和删除结点比单链表要复杂。双向链表中结点的插入分为在结点之前插入和在结点之后插入,插入操作要对四个引用进行操作
同样,删除操作也需要多多注意,其他的操作和单链表类似,不再赘述.
public class DBLinkList<T> : IListDS<T>
{
private DBNode<T> header;
public DBNode<T> Header
{
get { return header; }
set { header = value; }
}
public DBLinkList()
{
header = new DBNode<T>();
header.Next = null;
header.Prev = null;
}
/// <summary>
/// 获取长度
/// </summary>
/// <returns></returns>
public int GetLength()
{
DBNode<T> p = header;
int len = 0;
while (p != null)
{
++len;
p = p.Next;
}
return len;
}
/// <summary>
/// 清空操作
/// </summary>
public void Clear()
{
header = null;
}
/// <summary>
/// 判断线性表是否为空
/// </summary>
/// <returns></returns>
public bool IsEmpty()
{
if (header.Data == null)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 查找节点
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
private DBNode<T> FindNode(int i)
{
if (IsEmpty())
{
Console.Write("list is empty");
return null;
}
if (i < 1)
{
Console.Write("Index is error");
return null;
}
DBNode<T> current = new DBNode<T>();
current = header;
int j = 1;
while (current.Next != null && j < i)
{
++j;
current = current.Next;
}
return current;
}
/// <summary>
/// 插入操作,在第i个节点前面
/// </summary>
/// <param name="item"></param>
/// <param name="i"></param>
public void Insert(T item, int i)
{
DBNode<T> current = FindNode(i);
DBNode<T> newNode = new DBNode<T>(item);
if (current != null)
{
current.Prev.Next = newNode;
newNode.Next = current;
newNode.Prev = current.Prev;
current.Prev = newNode;
}
else
{
Console.Write("the node is not exist!");
}
}
/// <summary>
/// 插入操作,在第i个节点后面插入item
/// </summary>
/// <param name="item"></param>
/// <param name="i"></param>
public void InsertBack(T item, int i)
{
DBNode<T> current = FindNode(i);
DBNode<T> newNode = new DBNode<T>(item);
if (current != null)
{
current.Next.Prev = newNode;
newNode.Prev = current;
newNode.Next = current.Next;
current.Next = newNode;
}
else
{
Console.Write("the node is not exist!");
}
}
/// <summary>
/// 附加操作,线性表未满,将值为item的新元素添加到末尾
/// </summary>
/// <param name="item"></param>
public void Append(T item)
{
DBNode<T> newNode = new DBNode<T>(item);
DBNode<T> p = new DBNode<T>();
if (header == null)
{
header = newNode;
return;
}
p = header;
while (p.Next != null)
{
p = p.Next;
}
p.Next = newNode;
}
/// <summary>
/// 删除操作
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public T Delete(int i)
{
DBNode<T> current = FindNode(i);
if (current != null)
{
current.Prev.Next = current.Next;
current.Next.Prev = current.Prev;
current.Prev = null;
current.Next = null;
return current.Data;
}
else
{
Console.Write("the node is not exist!");
return default(T);
}
}
/// <summary>
/// 取表元
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public T GetElem(int i)
{
DBNode<T> current = FindNode(i);
if (current != null)
{
return current.Data;
}
else
{
Console.Write("the node is not exist!");
return default(T);
}
}
/// <summary>
/// 按值查找
/// </summary>
/// <param name="value"></param>
/// <returns>-1:链表或参数异常;0:节点不存在;1:值代表的位置</returns>
public int Locate(T value)
{
if (IsEmpty())
{
Console.Write("list is empty");
return -1;
}
if (value == null)
{
Console.Write("value is empty");
return -1;
}
DBNode<T> current = new DBNode<T>();
current = header;
int result = 0;
while (current.Next != null)
{
if (current.Data.Equals(value))
{
result = 1;
}
}
return result;
}
}
此外,循环链表的基本操作与单链表大体相同,只是判断链表结束的条件并不是判断结点的引用域是否为空,
而是判断结点的引用域是否为头引用,其它没有较大的变化
发表评论
-
CMPP短信网关客户端发送程序
2010-04-06 11:12 4717最近无聊,玩了玩ubuntu ... -
C#编程中的预处理指令
2010-01-13 11:22 1401在C#中, 虽然编译器没有单独的预处理器,但在处理预处理指令时 ... -
vs 打包winform程序步骤经验总结
2010-01-06 09:47 58451、 应用程序文件夹 : 在应用程序文件夹下新建一文件夹重名为 ... -
处理资源 'http://localhost/ws/Service.asmx' 时出错(iis,.netframework安装顺序造成的错)
2009-12-30 17:10 1909刚刚学习webservices,很多东西都不懂。写了个最简单的 ... -
图解在VS2005利用NUnit进行测试
2009-12-21 12:53 1555一、介绍NUnit是一款用于在.net环境进行单元测试的工具, ... -
如何编写单元测试用例(转载自CSDN)
2009-12-17 17:01 3161一、 单元测试的概念 ... -
NUnit2.0详细使用方法
2009-12-17 17:00 10685 .测试生命周期合约 如果记得test case的定义,其中 ... -
NUnit2.0详细使用方法
2009-12-17 16:58 11631、初识NUnitNUnit是一个开源单元测试框架,它提高一套 ... -
在.NET环境中使用单元测试工具Nunit
2009-12-17 16:56 1057简介编写单元测试是一 ... -
.NET命名空间使用介绍
2009-12-17 11:29 1712在ASP.NET中,.NET Framework为我们 ... -
一种清晰而又简单通用的分页算法
2009-12-17 10:03 6090分页,是WEB开发中面对的最常见的编程,实现方法多种多样。我也 ... -
读书笔记c#高级编程 委托和事件
2009-12-17 09:49 1097在C#中使用一个类时,分两个阶段。首先需要定义这个类,即告诉编 ... -
深入理解C#中的委托和事件:委托的定义
2009-12-16 16:04 1642委托和事件在 .Net Framework中的应用非常广泛,然 ... -
C#委托和事件(简单示例)
2009-12-16 15:46 38301.委派的实现过程。 首先来看一下委派,委派其实就是方法的传 ... -
关于配置文件的读取
2009-11-18 16:52 2069在1.0/1.1版本,都流行的 ... -
C# WInForm 无框窗体移动
2009-11-12 13:56 2014调用APIusing System.Runtime.Inter ... -
在C# 中如何动态地添加控件
2009-09-09 11:05 3648通常在写程序的时候 ... -
ListBox相互移动
2009-08-14 17:33 1430using System;using System.Colle ... -
TreeView-demo
2009-08-14 17:22 1318using System;using System.Co ... -
TreeView高效绑定数据
2009-08-13 17:28 4100前俩个项目都是做政府的门户网,他们的栏目、部门都要以树形展示, ...
相关推荐
主要介绍了C#数据结构之双向链表(DbLinkList),结合实例形式较为详细的讲解了双向链表的概念及C#实现双向链表的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
链表:单链表,双向链表,循环链表 栈,队列 二叉树应用-表达式求值 树的操作 图 二分查找 排序算法:插入排序,选择排序,冒泡排序 -全是C#,附上Viso图和一些解释
各种数据结构、算法及实用的C#源代码 C#,双向链表(Doubly Linked List)归并排序(Merge Sort)算法与源代码 1 双向链表 双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继和...
各种数据结构、算法及实用的C#源代码。C#,双向链表(Doubly Linked List)快速排序(Quick Sort)算法与源代码。双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继和直接前驱。...
双向链表的结点结构示意图如图所示。 双向链表结点的定义与单链表的结点的定义很相似, ,只是双向链表多了一个字段 prev。其实,双向链表更像是一根链条一样,你连我,我连你,不清楚,请看图。 双向链表结点类的...
本c#程序源码包含单链表,双向链表,循环链表的完整应用。
各种数据结构、算法及实用的C#源代码 C#,递归方法实现双向链表(Doubly Linked List)的反转(Reverse)算法与源代码 递归算法的执行过程分递推和回归两个阶段。在递推阶段,把较复杂的问题(规模为n)的求解推到比...
录 I 第1章绪论 1 1 1 数据结构 1 1 1 1 学习数据结构的必要性 1 1 1 2 基本概念和术语 1 1 2 算法 4 1 2 1算法的特性 4 1 2 2算法的评价标准 5 ...2 4 1 双向链表 61 2 4 2循环链表 64 2 5 C#中的线性表 64 本章小结 ...
主要介绍了C#模拟链表数据结构的实例解析,包括队双向链表的模拟方法,例子中队链表的操作也有很好的说明,需要的朋友可以参考下
2.4.1 双向链表.............................................................................................................61 2.4.2 循环链表...............................................................
目录 I 第1章绪论 1 1 1 数据结构 1 1 1 1 学习数据结构的必要性 1 1 1 2 基本概念和术语 1 1 2 算法 4 1 2 1算法的特性 4 1 2 2算法的评价标准 5...2 4 1 双向链表 61 2 4 2循环链表 64 2 5 C#中的线性表 64 本章小结 ...
2.4.1 双向链表.............................61 2.4.2循环链表..............................64 2.5 C#中的线性表.................................64 本章小结........67 习题二............67 第3章栈和队列......
将数据结构与C#语言和.NET框架结合是本书的一大特点。本书分为8章,第1章介绍了数据结构和算法的基本概念及本书用到的数学和C#的知识;第2章至第6章分别讨论了线性表、栈和队列、串和数组、树型结构和图结构等常用的...
链表分为①单链表,②单向循环链表,③双向链表,④双向循环链表。 介绍各种各样链表之前,我们要明白这样一个概念。什么是结点。在存储数据元素时,除了存储数据元素本身的信息外,还要存储与它相邻的数据元素的...
将数据结构与C#语言和.NET框架结合是本书的一大特点。本书分为8章,第1章介绍了数据结构和算法的基本概念及本书用到的数学和C#的知识;第2章至第6章分别讨论了线性表、栈和队列、串和数组、树型结构和图结构等常用的...
2.4.1 双向链表.............................................................................................................61 2.4.2循环链表................................................................
将数据结构与C#语言和.NET框架结合是本书的一大特点。本书分为8章,第1章介绍了数据结构和算法的基本概念及本书用到的数学和C#的知识;第2章至第6章分别讨论了线性表、栈和队列、串和数组、树型结构和图结构等常用的...