The Messenger of Allah placed the men in front of the young boys and the women behind the young boys. This is related by Ahmad and Abu Dawud.
Abu Hurairah reported that the Messenger of Allah said: “The best rows for the men are the first rows and the worst rows for them are the last rows. The best rows for the women are the last rows and the worst for them are the front rows.” The last rows are the best for the women because they are farther away from the men as against the first rows that are nearest to men’s rows. This is related by the group except al-Bukhari.