## 12. TUTORIAL 006 : Edges order.

In this tutorial, we will learn how to change edges order in the graph edges adjacency list (please visit Wikipedia: Adjacency and degree for more details ). Indeed, it can be useful to sort the edges considering a metric.

### 1. Creation of the graph and its edges

We will create a graph with 4 nodes and 4 edges. Their "id number" will start from 0 just like in the figure below : Following is the sample of code that created such a graph:

```int main() {
//create an empty graph
Graph *graph=tlp::newGraph();

//build the graph

```

As you can see, node 0 has three edges : edge 1,edge 2 and edge 3. And if we display its edges adjacency list (see last section for function ` void displayAdjacency(node n, Graph *graph) ` ) we obtain the following output :

` 1 2 3  `

### 2. Swap edges

Swapping edges can be easily done with the function, ` void Graph::swapEdgeOrder ( const node, const edge,const edge)` that will, as said swap two edges in the adjacent list of a node. Following is an example of its use :

```  //swap e1 and e3
graph->swapEdgeOrder(n0, e1, e3);
```

As you can see, the adjacency list has changed :

`  3 2 1  `

### 3. Setting an order

An other way to change the edges order is to use a vector of type edge and the function : ` void Graph::setEdgeOrder (const node, const std::vector < edge > )`, following is an example that will replace e1 and e3 in their original order :

```  vector<edge> tmp(2);
tmp=e1;
tmp=e3;
graph->setEdgeOrder(n0,tmp);
```

And the new order :

`  1 2 3  `

### Source Code

```#include <iostream>
#include <tulip/Graph.h>
#include <tulip/MutableContainer.h>

/**
* Tutorial 006
*
* Create a graph
* Order the edges around the nodes
*/

using namespace std;
using namespace tlp;

void buildGraph(Graph *graph) {
}

void displayAdjacency(node n, Graph *graph) {
Iterator<edge>*ite=graph->getInOutEdges(n);
while(ite->hasNext())
cout << ite->next().id << " ";
delete ite;
cout << endl;
}

int main() {
//create an empty graph
Graph *graph=tlp::newGraph();

//build the graph

//display current order of edge around n1

//swap e1 and e3
graph->swapEdgeOrder(n0,e1,e3);

//display the new order of edge around n1