C#環形鏈表

來源:互聯網
上載者:User
 

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; }
        }
    }

關於這種結構的使用:
我曾經想做一個聊天的小程式,聊天需要展示儲存資料,卻不需要永久。所以說一個臨時的儲存空間就特別的需要,或者叫緩衝。
這樣的一個環形鏈表就能實現我所需要的功能,正向插入,反向尋找。對於資料緩衝來說還是非常不錯的。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.