Facebook
From ALG, 9 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Diagnostics;
  12. using System.Collections.Generic;
  13.  
  14.  
  15. namespace Project2
  16. {
  17.     struct Pair
  18.     {
  19.         public int key;
  20.         public double value;
  21.     }
  22.  
  23.     class PriorityQueue
  24.     {
  25.         private SortedList<int,double> PseudoQueue;
  26.         private double value;
  27.         private int key;
  28.  
  29.         public int Key
  30.         {
  31.             get
  32.             {
  33.                 return key;
  34.             }
  35.         }
  36.  
  37.         public double Value
  38.         {
  39.  
  40.             get
  41.             {
  42.                 return value;
  43.             }
  44.         }
  45.         public bool Empty
  46.         {
  47.             get
  48.             {
  49.                 return PseudoQueue.Count == 0;
  50.             }
  51.         }
  52.  
  53.         public PriorityQueue()
  54.         {
  55.             PseudoQueue = new SortedList<int,double>();
  56.         }
  57.  
  58.         public void push(int key, double Value)
  59.         {
  60.             PseudoQueue.Add(key, Value);
  61.         }
  62.  
  63.         public void pop()
  64.         {
  65.            
  66.  
  67.            
  68.                 key = PseudoQueue.Keys.ElementAt(0);
  69.                 value = PseudoQueue[key];
  70.                 PseudoQueue.Remove(key);
  71.                        
  72.         }
  73.  
  74.  
  75.  
  76.        
  77.  
  78.         public int GetCount()
  79.         {
  80.             return PseudoQueue.Count;
  81.         }
  82.     }
  83.  
  84.  
  85.     class Program
  86.     {
  87.         static void Main(string[] args)
  88.         {
  89.             PriorityQueue prior = new PriorityQueue();
  90.             prior.push(1, 2.0);
  91.             prior.push(10, 3.0);
  92.             prior.push(41, 4.0);
  93.             prior.push(12, 5.0);
  94.  
  95.             prior.pop();
  96.             Console.WriteLine("key->{0} value->{1}", prior.Key,prior.Value);
  97.             prior.pop();
  98.             Console.WriteLine("key->{0} velue->{1}", prior.Key, prior.Value);
  99.             prior.pop();
  100.             Console.WriteLine("key->{0} velue->{1}", prior.Key, prior.Value);
  101.             prior.pop();
  102.             Console.WriteLine("key->{0} velue->{1}", prior.Key, prior.Value);
  103.            
  104.             Console.ReadKey();
  105.         }
  106.     }
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.    
  118.  
  119.