Optimus_P, this doesn't look like homework to me. Reversing a list of patches may be necessary to back them all out correctly. I do agree that "sed" is not a great choice. But we need more than just "sort". We can't assume that the data is currently sorted.
MBGPS, it looks like you completely overwrite the file on each iteration. If you don't have the "rev" command, try this:
nl -ba input | sort -nr | cut -f2- > output