title: Priority Queue in swift
body: <p>I'm trying to implement a version of Dijkstra Algorithm to find the shortest route for a bus to take from start to end. Unfortunately, I cannot seem to find a library or other way that swift provides a type of priority queue so it seems I will have to code my own.</p>
  
  <p>This being said, can anyone point me in the right direction to do this?</p>
  
  <p>Currently my thinking is as follows:</p>
  
  <p>Write a class which will hold the priority array. In this class there will be a method which receives a value, adds it to the priority array and then sorts it according to priority (In this case, distance). There will also be a get function which returns the highest priority item from the array.</p>
  
  <p>I would like to know if I'm close or still way off in my understanding of a priority queue.</p>
  
  <p>Thank you.</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>This is my code so far. Seems too short and brutal... I must be missing something in terms of the concept.</p>
  
  <pre><code>var priorityQueue = Dictionary&lt;String, Int&gt;()
  var firstElement: String = ""
  
  func push(name: String, distance: Int)
  {
      priorityQueue[name] = distance
      var myArr = Array(priorityQueue.keys)
      var sortedKeys = sort(myArr) {
          var obj1 = self.priorityQueue[$0] // get obj associated w/ key 1
          var obj2 = self.priorityQueue[$1] // get obj associated w/ key 2
          return obj1 &gt; obj2
      }
  
      firstElement = myArr[0]
      var tempPriorityQueue = Dictionary&lt;String, Int&gt;()
      for val in myArr
      {
          tempPriorityQueue[val] = priorityQueue[val]
      }
  
      priorityQueue = tempPriorityQueue
  }
  
  func pop() -&gt; String
  {
      priorityQueue.removeValueForKey(firstElement)
  }
  </code></pre>