Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. using System;
  2.  
  3. namespace PriorityQueue
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. PriorityQueue PQ = new PriorityQueue();
  10. PQ.push(3, "Clear drains");
  11. PQ.push(4, "Feed cat");
  12. PQ.push(5, "Make tea");
  13. PQ.push(1, "Solve RC tasks");
  14. PQ.push(2, "Tax return");
  15.  
  16. while (!PQ.Empty)
  17. {
  18. var Val = PQ.pop();
  19. Console.WriteLine(Val[0] + " : " + Val[1]);
  20. }
  21. Console.ReadKey();
  22. }
  23. }
  24.  
  25. class PriorityQueue
  26. {
  27. private System.Collections.SortedList PseudoQueue;
  28.  
  29. public bool Empty
  30. {
  31. get
  32. {
  33. return PseudoQueue.Count == 0;
  34. }
  35. }
  36.  
  37. public PriorityQueue()
  38. {
  39. PseudoQueue = new System.Collections.SortedList();
  40. }
  41.  
  42. public void push(object Priority, object Value)
  43. {
  44. PseudoQueue.Add(Priority, Value);
  45. }
  46.  
  47. public object[] pop()
  48. {
  49. object[] ReturnValue = { null, null };
  50. if (PseudoQueue.Count > 0)
  51. {
  52. ReturnValue[0] = PseudoQueue.GetKey(0);
  53. ReturnValue[1] = PseudoQueue.GetByIndex(0);
  54.  
  55. PseudoQueue.RemoveAt(0);
  56. }
  57. return ReturnValue;
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement