The list class has the function of a hash table

Source: Internet
Author: User

Using System;

Namespace Study
{
<summary>
Summary description of the 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&LT;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;
}
}
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.