Implemented sorting of arrays before printing