I have a matrix of numbers representing the nodal points as follows:

```
Element No. Nodes
1 1 2 3 4
2 5 6 7 8
3 2 3 9 10
...........................
...........................
x 9 10 11 12
...........................
```

so this is a matrix of numbers 4 x n

Elements 1 and 3 are neighbours (as they share nodes 2 3). Similarly elements 3 and x are neighbours (they share nodes 9 and 10). I want to sort the matrix in such a way all the elements are sequentially arranged.