internal int priority; //lower priority is higher
 public DoubleListNode(int data, int priority, DoubleListNode next, DoubleListNode prev)
 {
     this.data     = data;
     this.next     = next;
     this.prev     = prev;
     this.priority = priority;
 }
        internal void Enqueue(DoubleListNode newNode)
        {
            if (head == null)
            {
                head = newNode;
                return;
            }
            if (newNode.priority < head.priority)
            {
                newNode.next = head;
                head.prev    = newNode;
                head         = newNode;
                return;
            }
            DoubleListNode cur = head;

            while (cur.next != null && cur.next.priority < newNode.priority)
            {
                cur = cur.next;
            }
            if (cur.next == null)
            {
                cur.next     = newNode;
                newNode.prev = cur;
            }
            else
            {
                cur.next.prev = newNode;
                newNode.next  = cur.next;
                cur.next      = newNode;
                newNode.prev  = cur;
            }
        }
 public DoubleListNode(int data, int priority)
 {
     this.data     = data;
     this.priority = priority;
     this.prev     = null;
     this.next     = null;
 }
 public DoubleListNode(int data, int priority)
 {
     this.data = data;
     this.priority = priority;
     this.prev = null;
     this.next = null;
 }
        internal int priority; //lower priority is higher

        #endregion Fields

        #region Constructors

        public DoubleListNode(int data, int priority, DoubleListNode next, DoubleListNode prev)
        {
            this.data = data;
            this.next = next;
            this.prev = prev;
            this.priority = priority;
        }
        internal DoubleListNode Deque()
        {
            if (head == null)
            {
                return(null);
            }
            DoubleListNode temp = head;

            head = head.next;
            return(temp);
        }
 public PriorityQueue()
 {
     head = null;
 }
 internal void Enqueue(DoubleListNode newNode)
 {
     if (head == null)
     {
         head = newNode;
         return;
     }
     if (newNode.priority < head.priority)
     {
         newNode.next = head;
         head.prev = newNode;
         head = newNode;
         return;
     }
     DoubleListNode cur = head;
     while (cur.next != null && cur.next.priority < newNode.priority)
     {
         cur = cur.next;
     }
     if (cur.next == null)
     {
         cur.next = newNode;
         newNode.prev = cur;
     }
     else
     {
         cur.next.prev = newNode;
         newNode.next = cur.next;
         cur.next = newNode;
         newNode.prev = cur;
     }
 }
 internal DoubleListNode Deque()
 {
     if (head == null)
         return null;
     DoubleListNode temp = head;
     head = head.next;
     return temp;
 }
Exemple #10
0
 public PriorityQueue()
 {
     head = null;
 }