Exemple #1
0
        /// <summary>
        /// 从尾部弹出一个元素
        /// </summary>
        /// <returns></returns>
        public byte pop()
        {
            if (Count == 0)
            {
                throw new Exception("队列内无元素");
            }
            byte p = Foot.Value;

            if (Current == Foot)
            {
                Current = null;
            }
            if (_count == 1)
            {
                Head    = null;
                Foot    = null;
                Current = null;
            }
            else
            {
                Foot      = Foot.prev;
                Foot.next = null;
            }
            _count--;
            return(p);
        }
Exemple #2
0
        /// <summary>
        /// 从头部弹出一个元素
        /// </summary>
        /// <returns></returns>
        public byte shift()
        {
            if (Count == 0)
            {
                throw new Exception("队列内无元素");
            }
            byte p = Head.Value;

            if (Current == Head)
            {
                Current = null;
            }
            if (_count == 1)
            {
                Head    = null;
                Foot    = null;
                Current = null;
            }
            else
            {
                Head      = Head.next;
                Head.prev = null;
            }
            _count--;
            return(p);
        }
Exemple #3
0
        /// <summary>
        /// 转化为数组
        /// </summary>
        /// <returns></returns>
        public byte[] toArray()
        {
            byte[]    rst = new byte[Count];
            ByteClass p   = Head;

            for (int i = 0; i < Count; i++)
            {
                rst[i] = p.Value;
                p      = p.next;
            }
            return(rst);
        }
Exemple #4
0
        //在头部添加一个元素
        public void unshift(byte b)
        {
            ByteClass nb = new ByteClass(b);

            if (Count == 0)
            {
                Head    = nb;
                Current = nb;
                Foot    = nb;
            }
            else
            {
                nb.next   = Head;
                Head.prev = nb;
                Head      = nb;
            }
            _count++;
        }
Exemple #5
0
        /// <summary>
        /// 在队列尾部添加一个元素
        /// </summary>
        /// <param name="b"></param>
        public void push(byte b)
        {
            var nb = new ByteClass(b);

            if (Count == 0)
            {
                Head    = nb;
                Current = nb;
                Foot    = nb;
            }
            else
            {
                nb.prev   = Foot;
                Foot.next = nb;
                Foot      = nb;
            }
            _count++;
        }