上一篇:Destructors in C# >>
链表类具有哈希表的功能
using System;
namespace Study
{
/// <summary>
/// CChain 的摘要说明。
/// </summary>
public class CChain
{
public class CChainNode
{
public object Data;
public CChainNode NextChainNode;
public CChainNode PreviousChainNode;
public object Tag;
public string Key;
public CChainNode()
{
this.Data=null;
this.Tag=null;
this.Key=null;
this.NextChainNode=this.PreviousChainNode=null;
}
public CChainNode(object vData,object vTag,string vKey)
{
this.Data=vData;
this.Tag=vTag;
this.Key=vKey;
this.NextChainNode=this.PreviousChainNode=null;
}
}
public class CChainIterator
{
private CChainNode pCurrentChainNode,pFirstChainNode,pLastChainNode;
private bool pbFirst,pbLast;
public CChainIterator(CChainNode vFirstChainNode,CChainNode vLastChainNode)
{
this.pCurrentChainNode=this.pFirstChainNode=this.pLastChainNode=null;
if(vFirstChainNode!=null)
{
pCurrentChainNode=pFirstChainNode=vFirstChainNode;
pbFirst=false;
}
if(vLastChainNode!=null)
{
pCurrentChainNode=pLastChainNode=vLastChainNode;
pbLast=false;
}
}
public CChainNode CurrentChainNode
{
get
{
return this.pCurrentChainNode;
}
}
public bool NextChainNode()
{
if(this.pFirstChainNode==null)
{
return false;
}
if(pCurrentChainNode==pFirstChainNode && pbFirst==false)
{
pbFirst=true;
return true;
}
else
{
pCurrentChainNode=pCurrentChainNode.NextChainNode;
if(pCurrentChainNode ==null)
{
return false;
}
else
{
return true;
}
}
}
public bool PreviousChainNode()
{
if(this.pLastChainNode==null)
{
return false;
}
if(pCurrentChainNode==pLastChainNode && pbLast==false)
{
pbLast=true;
return true;
}
else
{
pCurrentChainNode=pCurrentChainNode.PreviousChainNode;
if(pCurrentChainNode ==null)
{
return false;
}
else
{
return true;
}
}
}
}
public CChainNode FirstChainNode;
public CChainNode LastChainNode;
public CChainNode CurrentChainNode;
public CChain()
{
this.FirstChainNode=this.LastChainNode=this.CurrentChainNode =null;
}
~CChain()
{
}
public bool IsEmpty()
{
if(this.FirstChainNode==null)
{
return true;
}
else
{
return false;
}
}
public bool AppendChainNode(CChainNode vChainNode)
{
if(vChainNode==null)
{
return false;
}
else
{
if(this.FirstChainNode==null)
{
this.FirstChainNode=vChainNode;
this.FirstChainNode.PreviousChainNode=null;
this.FirstChainNode.NextChainNode=null;
this.LastChainNode=this.CurrentChainNode=this.FirstChainNode;
}
else
{
this.CurrentChainNode.NextChainNode=vChainNode;
vChainNode.PreviousChainNode=this.CurrentChainNode;
vChainNode.NextChainNode=null;
this.LastChainNode=this.CurrentChainNode=vChainNode;
}
return true;
}
}
public bool InsertChainNode(int Index,CChainNode vChainNode)
{
CChainNode pCn;
int pCount=0;
CChain.CChainIterator pCi=new CChainIterator(this.FirstChainNode,null);
if(vChainNode==null || Index<0)
{
return false;
}
if(Index==0)
{
pCn=this.FirstChainNode;
vChainNode.NextChainNode=pCn;
pCn.PreviousChainNode=vChainNode;
this.FirstChainNode=vChainNode;
vChainNode.PreviousChainNode=null;
return true;
}
while(pCi.NextChainNode()==true)
{
pCount++;
if(pCount==Index)
{
pCn=pCi.CurrentChainNode.NextChainNode;
pCi.CurrentChainNode.NextChainNode=vChainNode;
vChainNode.PreviousChainNode=pCi.CurrentChainNode;
vChainNode.NextChainNode=pCn;
if(pCn!=null)
{
pCn.PreviousChainNode=vChainNode;
}
return true;
}
}
return false;
}
public bool ContainsKey(string vKey)
{
CChain.CChainIterator pCi=new CChainIterator(this.FirstChainNode,null);
while(pCi.NextChainNode()==true)
{
if(pCi.CurrentChainNode.Key ==vKey)
{
return true;
}
}
return false;
}
public CChain.CChainNode Item(string vKey)
{
CChain.CChainIterator pCi=new CChainIterator(this.FirstChainNode,null);
while(pCi.NextChainNode()==true)
{
if(pCi.CurrentChainNode.Key ==vKey)
{
return pCi.CurrentChainNode;
}
}
return null;
}
public object ItemData(string vKey)
{
CChain.CChainIterator pCi=new CChainIterator(this.FirstChainNode,null);
while(pCi.NextChainNode()==true)
{
if(pCi.CurrentChainNode.Key ==vKey)
{
return pCi.CurrentChainNode.Data;
}
}
return null;
}
public int ChainNodeCount()
{
int pCount=0;
CChain.CChainIterator pCi=new CChainIterator(this.FirstChainNode,null);
while(pCi.NextChainNode()==true)
{
pCount++;
}
return pCount;
}
}
}
下一篇:C#中委托,事件理解入门 >>
相关文章:
- · 用一个留言簿说明C#操作XML的完全过程
- · 递归枚举排列、组合的C#源码
- · C#反编译微软MSDN2003的帮助文档,并将反编译结果保存到一个SQLSERVER数据库中
- · 用C#轻松在DOTNET中实现缩略图
- · c#中结构与类的区别
- · DES加密算法在C#下的实现
- · C#对XML操作:建立XML(3)
- · 上传图片画带阴影的水印.(C#)
- · Destructors in C#
- · 特洛伊木马服务器源代码(C#)
- · [C#]I/O完成端口的类定义和测试实例
- · 选择文件夹的对话框控件c#
- · C#实现Web文件的上传
- · 用C#实现生成PDF文档
- · 用C#实现生成PDF文档
- · 一个FTP客户端的C#代码
- · C# struct & class Differences
- · C++编程人员容易犯的10个C#错
- · C#冒泡算法!
- · 如何在C#的WinForm中制作饼状图和柱状图
- · 使用响应文件编译C#源文件
- · 用C#写vs插件中的一些Tip
- · 用C#生成中文汉字验证码的基本原理
- · 用托盘控制windows服务的c#实现
- · ASP.NET的实时天气及24小时天气预报(C#)
- · 使用C#代码实现增加用户帐号
- · 用c#写的smtp邮件发送类
- · C# Builder 实现POP3信箱的监视
- · 一个有KeepConnection开关的C#的Database类
- · 一个用C#写的词法分析程序
- · 利用自定义事件实现不同窗体间的通讯 -- C#篇
- · 用C#开发.NET CF 蓝牙通信模块
- · 关于C#下写的Web Service 服务在Delphi下调用时的问题
- · 用C#写的一个简单屏幕保护程序
- · .Net/C#: 利用反射编写通用的 rss 2.0 的 reader
- · C# Programming guidlines
- · QQ验证码识别源代码(C#/NET1.1)
- · C#教学经验谈(3):储蓄计算器的源程序
