title: C++ vector sort gives 0 as output
body: <p>I'm trying to sort the contents of the vector in ascending order I know how to do that but when I'm tring it I'm getting output as 0.I tried sorting in descending order and I'm getting the correct answer in that case.</p>
  <pre><code>#include &lt;iostream&gt;
  #include&lt;vector&gt;
  #include&lt;algorithm&gt;
  using namespace std;
  class Edge {
   public:
    int node1;
    int node2;
    int edge_weight;
    
    Edge()   
    {}
  
    Edge(int n1,int n2,int w)   
    {
         node1=n1;
         node2=n2;
         edge_weight=w;   
     } 
  };
  
  bool mycompare(Edge e1,Edge e2) 
  {   
    return e1.edge_weight&lt;e2.edge_weight; 
  }
  
  int main() 
  {   
    int V, E;   
    cin &gt;&gt; V &gt;&gt; E;   
    vector&lt;Edge&gt; v(E);   
    int *parent=new int[V];
    for(int i=0;i&lt;V;i++)   
    {
      parent[i]=i;   
    }   
    
    int count=0;  
    for(int i=0;i&lt;E;i++)
    {
      int s1,s2,weight;
      cin&gt;&gt;s1&gt;&gt;s2&gt;&gt;weight;
      Edge e(s1,s2,weight);
        
      v.push_back(e);
    }     
    
    sort(v.begin(),v.end(),mycompare);    
    for(int i=0;i&lt;E;i++)
    {
      cout&lt;&lt;v[i].node1&lt;&lt;&quot; &quot;&lt;&lt;v[i].node2&lt;&lt;&quot; &quot;&lt;&lt;v[i].edge_weight&lt;&lt;endl;
    }   
    return 0; 
  } 
  </code></pre>
  <p><strong>Input:</strong></p>
  <blockquote>
  <p>4 4</p>
  <p>0 1 3</p>
  <p>0 3 5</p>
  <p>1 2 1</p>
  <p>2 3 8</p>
  </blockquote>
  <p><strong>Output in case of descending order:</strong></p>
  <blockquote>
  <p>2 3 8</p>
  <p>0 3 5</p>
  <p>0 1 3</p>
  <p>1 2 1</p>
  </blockquote>
  <p><strong>Output in case of ascending order:</strong></p>
  <blockquote>
  <p>0 0 0</p>
  <p>0 0 0</p>
  <p>0 0 0</p>
  <p>0 0 0</p>
  </blockquote>
  <p>Here, the output in case of descending order is correct but for ascending
  I'm getting 0 as the value for all the nodes.</p>