title: Dijkstra's algorithm in c++ infinite loop
body: <p>I was trying to implement Dijkstras's algorithm in c++. Now i have trouble debugging. Somewhere in my code there is an infinite loop. And my graph implementation sucks. if you have any ideas what is wrong with my code even if it is not about the main problem tell me. </p>
  
  <p>I don't need somebody elses code i need it to be my code but fixed so i can find my mistakes in code and better understand it (i only understand my codes sadly c++ compiler doesn't). </p>
  
  <p>Here is my code: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;limits.h&gt;
  #include &lt;queue&gt;
  using namespace std;
  
  vector &lt; vector&lt;int&gt; &gt; graf;
  int fromnode, tonode;
  
  struct nodeinfo
  {
      //this contains info about a node
      bool visited = 0;
      int dis = INT_MAX/2;
  };
  nodeinfo sample;
  vector&lt;nodeinfo&gt; info; // if visited
  queue&lt;int&gt; togo;
  
  // dijkstra algorithm
  void dijkstra(int currnode)
  {
      //visited current node
      info[currnode].visited = 1;
      //go see every node connected to the current one
      for(int i = 0; i &lt; graf[currnode].size(); i ++){
          if (graf[currnode][i] != INT_MAX/2 ) {
              // if visited push to queue and check distance
              if(info[i].visited== 0)
                  togo.push(i);
              info[i].dis = max(info[i].dis,info[currnode].dis + graf[currnode][i]);
          }
      }
  }
  
  
  int main()
  {
      //input n
      int n;
      cin &gt;&gt; n;
  
      //declaring variables
      graf.resize(n*2);
      info.resize(n*2);
      vector&lt;int&gt; fillin (100,INT_MAX/2);
      graf.insert(graf.begin(),100,fillin);
      int a,b,c;
  
      //input in graphinfo[graf[currnode][i
      for(int i = 0; i &lt; n; i ++){
          cin &gt;&gt; a &gt;&gt; b &gt;&gt; c;
          if (graf[a][b] &gt; c)
              graf[a][b] = graf[b][a] = c;
          cout &lt;&lt; i &lt;&lt; endl;
      }
      // input from witch node to go and where to go and
      cin &gt;&gt; fromnode &gt;&gt; tonode;
      info[fromnode].dis = 0;
      togo.push(fromnode);
      //dijkstra start
      while(!togo.empty()){
          dijkstra(togo.front());
      }
      // output
      cout &lt;&lt; info[tonode].dis &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>after i had put   <code>cout &lt;&lt; "at node " &lt;&lt; currnode &lt;&lt; endl;</code> at the beginning of dijskstra function using this input:</p>
  
  <p><a href="https://i.stack.imgur.com/0rEvV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0rEvV.png" alt="enter image description here"></a></p>
  
  <p>It was stuck on node 1:</p>
  
  <p><a href="https://i.stack.imgur.com/NSPGW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NSPGW.png" alt="enter image description here"></a></p>