public class Chain
{
//Chain proporty
public string ID;
public string name;
public string text;
public DateTime time;
//Chain relation
private object lastObj;
private object nextObj;
public object Next
{
get{return nextObj;}
set{nextObj=value;}
}
public object Previous
{
get{return lastObj;}
set{this.lastObj=value;}
}
public Chain(){}
}
public class ChainManager
{
int count;
Chain current;
public ChainManager(int num)
{
Chain fristChain = new Chain();
Chain chain = fristChain;
for (int i = 0; i < num-1; i++)
{
//chain property
chain.name = i.ToString();
//chain relation
Chain newChain=new Chain();
chain.Next = newChain;
newChain.Previous = chain;
chain = (Chain)chain.Next;
}
chain.name = "9";
chain.Next = fristChain;
fristChain.Previous = chain;
this.current = chain;
this.count = num;
}
public void Next()
{
current=(Chain)current.Next;
}
public void Previous()
{
current=(Chain)current.Previous;
}
public Chain CurrentChain
{
get { return current; }
set { current = value; }
}
public int Count
{
get { return count; }
}
}
關於這種結構的使用:
我曾經想做一個聊天的小程式,聊天需要展示儲存資料,卻不需要永久。所以說一個臨時的儲存空間就特別的需要,或者叫緩衝。
這樣的一個環形鏈表就能實現我所需要的功能,正向插入,反向尋找。對於資料緩衝來說還是非常不錯的。