Advertisement
Guest User

PriorityQueueF.cs

a guest
Jan 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Sztuczna_Inteligencja
  9. {
  10.     class PriorityQueueF<Element> : IFringe<Element>
  11.     {
  12.         private List<Tuple<int, Element>> queueElements = new List<Tuple<int, Element>>();
  13.  
  14.         public bool IsEmpty
  15.         {
  16.             get
  17.             {
  18.                 return queueElements.Count == 0;
  19.             }
  20.         }
  21.  
  22.         public Func<Element, int> ToGoalPath { get; set; }
  23.  
  24.         public void Add(Element element)
  25.         {
  26.             int i = 0;
  27.             for (i = 0; i < queueElements.Count; i++)
  28.                 if ((queueElements.Count == 0) || (ToGoalPath(element) <= queueElements[i].Item1) )
  29.                     break;
  30.                 queueElements.Insert(i, new Tuple<int, Element>(ToGoalPath(element), element));
  31.         }
  32.  
  33.         public Element Pop()
  34.         {
  35.             return queueElements[0].Item2;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement