예제 #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;
 }