Exemple #1
0
        public void EnQ(string v, int p)
        {
            priNode newone = new priNode(v, p);
            priNode data   = head;

            while (data.back != null)
            {
                if (data.Pri > newone.Pri)
                {
                    Count++;
                    if (data == head)
                    {
                        newone.back = data;
                        data.front  = newone;
                        head        = newone;
                    }
                    else
                    {
                        data.front.back = newone;
                        newone.front    = data.front;
                        newone.back     = data;
                        data.front      = newone;
                    }
                    return;
                }
                else
                {
                    data = data.back;
                }
            }

            if (data.Pri > newone.Pri)
            {
                Count++;
                if (data == head)
                {
                    newone.back = data;
                    data.front  = newone;
                    newone      = head;
                }
                else
                {
                    data.front.back = newone;
                    newone.front    = data.front;
                    newone.back     = data;
                    data.front      = newone;
                }
                return;
            }
            else
            {
                Count++;
                data.back    = newone;
                newone.front = data;
            }
        }
Exemple #2
0
        public string DeQ()
        {
            if (Count == 0)
            {
                return("해당 큐는 비었습니다");
            }
            else
            {
                string answer = head.value;
                head = head.back;
                Count--;

                return(answer);
            }
        }
Exemple #3
0
 public void PrintAllData()
 {
     if (Count != 0)
     {
         priNode data = head;
         while (data != null)
         {
             Console.WriteLine("데이터: {0}, 우선순위: {1}", data.value, data.Pri);
             data = data.back;
         }
     }
     else
     {
         Console.WriteLine("해당 큐는 비었습니다");
         return;
     }
 }
Exemple #4
0
        public string DeQ(out int p)
        {
            if (Count == 0)
            {
                p = 0;
                return("해당 큐는 비었습니다");
            }
            else
            {
                string answer = head.value;
                p    = head.Pri;
                head = head.back;
                Count--;

                return(answer);
            }
        }
Exemple #5
0
 public PriorityQueue(string v, int p)
 {
     head  = new priNode(v, p);
     Count = 1;
 }