title: Dijkstra's algorithm using the priority queue
body: <p>So I am trying to implement Dijkstra's algorithm using the priority queue data structure in java. Since  comparable operator in java cannot compare two variables, so i need to "modify its <code>Comparator</code>. How do I modify it ?</p>
  
  <pre><code> while(!Q.isEmpty()){
           int index = Q.peek().edge;
           long d = Q.peek().dis;
           Q.remove();
  
           if(d!=D[index]) continue; // HERE I AM CHECKING IF IT ALREADY PROCEEDED OR NOT
  
           for(int i=0;i&lt;maps[index].size();i++){
                 int e = maps[index].get(i).edge;
                  d =  maps[index].get(i).dis;
                  if(D[e]&gt;D[index]+d){
                      D[e]= D[index]+d;
                      Q.add(new Node(e,D[e])); // NEED TO MODIFY
                  }
           }
       }
  </code></pre>
  
  <p><br><br>Then i came across this code:</p>
  
  <pre><code> while (!q.isEmpty()) {
        long cur = q.remove();
        int curu = (int) cur;
        if (cur &gt;&gt;&gt; 32 != prio[curu])
          continue;
        for (Edge e : edges[curu]) {
          int v = e.t;
          int nprio = prio[curu] + e.cost;
          if (prio[v] &gt; nprio) {
            prio[v] = nprio;
            pred[v] = curu;
            q.add(((long) nprio &lt;&lt; 32) + v);
          }
  </code></pre>
  
  <p>How  <code>q.add(((long) nprio &lt;&lt; 32) + v);</code> and <code>cur &gt;&gt;&gt; 32 != prio[curu]</code> statements works. Please HElp.</p>