Implemented counting sort