Sorting is easy, there are all sorts of ways to do it. Google "sort algorithm".