欢迎光临
我们一直在努力

linkedqueue的实现-.net教程,算法/线

建站超值云服务器,限时71元/月

public class linkedqueue
{
        private class node
        {
                public object data;
                public node link;
        }
  
        private node front;
        private node rear;
  
        public linkedqueue()
        {
        }
  
        public bool isempty
        {
                get
                {
                        return front == null;
                }
        }
  
  
        public bool isfull
        {
                get
                {
                        node p;
  
                        try
                        {
                                p = new node();
                                return false;
                        }
                        catch
                        {
                                return true;
                        }
                }
        }
  
        public object first
        {
                get
                {
                        if(isempty)
                        {
                                throw new exception("queue is empty.");
                        }
  
                        return front.data;
                }
        }
  
        public object last
        {
                get
                {
                        if(isempty)
                        {
                                throw new exception("queue is empty.");
                        }
  
                        return rear.data;
                }
        }
  
        public linkedqueue add(object x)
        {
                node p;
  
                // create node for new element
                p = new node();
                p.data = x;
                p.link = null;
  
                if(front != null) // queue not empty
                {
                        rear.link = p;
                }
                else // queue empty
                {
                        front = p;
                }
  
                rear = p;
  
                return this;
        }
  
        public object delete()
        {
                node p;
                object x;
  
                if(isempty)
                {
                        throw new exception("queue is empty.");
                }
  
                        // save element in first node
                x = front.data;

  
                // delete first node
                p = front;
                front = front.link;
                p = null;
  
                return x;
        }

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » linkedqueue的实现-.net教程,算法/线
分享到: 更多 (0)

相关推荐

  • 暂无文章