title: sort graph edges in increasing order
body: <p>I am representing graphs using the standard adjacency list representation where each node is going out as an linked list. You can read more about adjacency list <a href="http://www.geeksforgeeks.org/graph-and-its-representations/" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Lets say below is my graph:</p>
  
  <pre><code>         10
      0--------1
      |  \     |
     6|   5\   |15
      |      \ |
      2--------3
          4
  </code></pre>
  
  <p>Adjacency list would look like as :</p>
  
  <pre><code>[0,  1,  2,  3]
   |   |   |   |
   10  10  6   6
   |   |   |   |
  [1] [0] [0] [2]
   |   |   |   |
   6   15  4   5
   |   |   |   |
  [2] [3] [3] [0]
   |   |   |   |
   |   |   |   15
      NULL     |
              [1]
               |
               |
              NULL
  </code></pre>
  
  <p>Since the graph is undirected, edges should be added from source to destination and from destination to source as well along with the weight of the edges. This is how code representation would looks like in that case.</p>
  
  <pre><code>// Linked list representation
  class Adj_Node {
    public:
      int data;
      int weight;
      Adj_Node* next;
  };
  
  // Adjacency list representation
  class Adj_List {
    public:
      Adj_Node* head;
  };
  
  // Graph representation
  class Graph {
    public:
      int vertices;
      Adj_List* source;
      Graph(int v) {
        vertices = v;
        source = new Adj_List[vertices];
  
        for (int i = 0; i &lt; vertices; ++i) {
          source[i].head = NULL;
        }
      }
      void addEdge(int, int, int);
      void printGraph();
  };
  
  // Creates an linked list node
  Adj_Node* createNode(int d) {
    Adj_Node* tmp = new Adj_Node;
    tmp-&gt;data   = d;
    tmp-&gt;weight = 0;
    tmp-&gt;next   = NULL;
  
    return tmp;
  }
  
  // Adds edge to both src and destination
  void Graph::addEdge(int src, int dest, int weight) {
    Adj_Node* node = createNode(dest);
    node-&gt;next = source[src].head;
    source[src].head = node;
    node-&gt;weight = weight;
  
    node = createNode(src);
    node-&gt;next = source[dest].head;
    source[dest].head = node;
    node-&gt;weight = weight;
  }
  
  void Graph::printGraph() {
    for(int i = 0; i &lt; vertices; ++i) {
    Adj_Node* n = source[i].head;
    std::cout &lt;&lt; i &lt;&lt; " = ";
    while(n != NULL) {
      std::cout &lt;&lt; n-&gt;data &lt;&lt; " " &lt;&lt; n-&gt;weight &lt;&lt; ", ";
      n = n-&gt;next;
    }
    std::cout &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>So, having said all of the above, I have above depiction linked list representation with me where each weighted edge of the graph is depicted as an node in an linked list.
  Question is : What are the ways you will suggest to get the edges in increasing order?</p>