How can i sort the adjacency list of graph representation

1->3,2,5
2->5,1
3->1
5->1,2
how can i make this to
1->2,3,5
2->1,5
3->1
5->1,2