title: Kruskal's algorithm (sort)
body: <p>I am reading a representation from a file and storing it in an adjacency list. Then I output the graph in "graphviz format" and perform a MST algorithm on the graph.
  Finally, I output the MST in "graphviz format". I am doing this in C++.</p>
  
  <p>My main question is with the algorithm. I'm implementing Kruskals algorithm and the sort function isn't working.</p>
  
  <p>When i compile it i get this error:</p>
  
  <blockquote>
    <p>instantiated from ‘void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator*, std::vector, std::allocator > > >, _Compare = bool (*)(Edges, Edges)]’</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;fstream&gt;
  #include &lt;map&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;cstdlib&gt;  
  #include &lt;utility&gt;   
  
  
  using namespace std;
  
  
  #define egdes pair&lt;int ,int &gt;
  #define MAX 9
  
  struct Edges
  {
      int weight;
      int first,second;
      char begin,end;
  };
  
      bool EdgeLess(Edges oneE,Edges twoE)
       {
          return oneE.weight &lt; twoE.weight;
       }  
  
  vector&lt;pair&lt;int ,Edges &gt; &gt; graph,MST;
  int parent[MAX],total ;
  
  
  bool openInputFile(ifstream &amp;inFile,char* argv);
  bool openOutputFile(ofstream &amp;outFile,char* argv);
  void readInputFile(ifstream &amp;inFile,vector&lt;Edges&gt; &amp;graph);
  int findSet(int x,int *parent);
  void kruskals();
  void makeSet();
  bool compareEdgW(Edges oneE,Edges twoE);
  
  int main (int argc,char **argv)
  {
  
      ifstream inFile;
      ofstream outFile;
      int u,v,w;
       int nodeCount;
      int edgeCount;
      char nodeName;
      Edges edge;
  
      vector&lt;Edges&gt; graph;
  
          cout&lt;&lt;"hey"&lt;&lt;endl;
   if(openInputFile(inFile,argv[1]) &amp;&amp; openOutputFile(outFile,argv[2]))
      {
          readInputFile(inFile,graph);
  
          outFile.close();
      }
  
      inFile &gt;&gt; nodeCount;
      inFile &gt;&gt; edgeCount;
  
      for( int i = 0;i &lt; edgeCount; i++)
      {
          cin &gt;&gt; u &gt;&gt; v &gt;&gt; w ; 
  //        graph.push_back(pair&lt;int ,Edges &gt;(w,edges(u,v)));
          graph.push_back(edge);
      }
  
      kruskals();
  
      makeSet();  
      return 0;
  }
  
  
  bool openInputFile(ifstream &amp;inFile,char* argv)
  {
      inFile.open("input.txt");
      if(!inFile)
      {
          cout&lt;&lt;"Oops!Input file did not open.\n";
          cout&lt;&lt;"Terminating the program.\n";
          return false;
      }
      return true;
  }
  bool openOutputFile(ofstream &amp;outFile,char* argv)
  {
      outFile.open("output.gv");
      if(!outFile)
      {
          cout&lt;&lt;"Hey!Oops!Input file did not open.\n";
          cout&lt;&lt;"Terminating the program.\n";
          return false;
      }
      return true;
  }
  void readInputFile(ifstream &amp;inFile,vector&lt;Edges&gt; &amp;graph)
  {
      int nodeCount;
      Edges edge;
  
      inFile &gt;&gt;nodeCount;
  
      char nodeName;
  
      for (int i = 0;i &lt; nodeCount;i++)
      {
          inFile &gt;&gt; nodeName;
  //        graph.insert(make_pair(nodeName,vector&lt;Edges&gt;()));
  
      }
      int edgeCount;
      inFile &gt;&gt; edgeCount;
  
      for (int i = 0;i &lt; edgeCount;i++)
      {
    //      inFile &gt;&gt;nodeName;
          Edges edge;
          inFile &gt;&gt; edge.begin;
          inFile &gt;&gt; edge.weight;
          inFile &gt;&gt; edge.end;
          graph.push_back(edge);
  
      }
  
  }
  int findSet(int x,int *parent)
  {
      if( x != parent[x])
          parent [x] = findSet(parent[x],parent);
      return parent[x];
  
  }
  
  void kruskals()
  {
      int pu;
      int pv;
      int edgeCount;
  
      sort(graph.begin(),graph.end (),EdgeLess);
      for (int i = 0;i &lt; edgeCount; i++) 
      {
          pu = findSet(graph[i].second.first,parent);
          pv = findSet(graph[i].second.second,parent);
          if(pu != pv)
          {   
              MST.push_back(graph[i]);
              total += graph[i].first;
              parent[pu] = parent[pv];
          }
      }
  }
  void makeSet()
  {
      unsigned long sizeNum;
      sizeNum = MST.size();
      for(int i = 0;i &lt; sizeNum;i++)
      {
          cout&lt;&lt; MST[i].second.first &lt;&lt;endl;
          cout&lt;&lt; MST[i].second.second &lt;&lt;endl;
          cout&lt;&lt; MST[i].first &lt;&lt;endl;
      }
          cout &lt;&lt; total &lt;&lt;endl;
  }
  </code></pre>