示例#1
0
 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;
 }
示例#2
0
        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;
            }
        }
示例#3
0
 public DoubleListNode(int data, int priority)
 {
     this.data     = data;
     this.priority = priority;
     this.prev     = null;
     this.next     = null;
 }
示例#4
0
 public DoubleListNode(int data, int priority)
 {
     this.data = data;
     this.priority = priority;
     this.prev = null;
     this.next = null;
 }
示例#5
0
        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;
        }
示例#6
0
        internal DoubleListNode Deque()
        {
            if (head == null)
            {
                return(null);
            }
            DoubleListNode temp = head;

            head = head.next;
            return(temp);
        }
示例#7
0
 public PriorityQueue()
 {
     head = null;
 }
示例#8
0
 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;
     }
 }
示例#9
0
 internal DoubleListNode Deque()
 {
     if (head == null)
         return null;
     DoubleListNode temp = head;
     head = head.next;
     return temp;
 }
示例#10
0
 public PriorityQueue()
 {
     head = null;
 }