This should be a no brainer for any agent worth his/her commission. You simply use the same closing attorney or escrow company to close both transactions. The buyer will need to bring cash to closing, or a note from the lender if being financed. Therefore, there is no need to wait for a check to clear. In most cases, your agent should have it in your contract that you have until close of business or some other designated time/date to get out of the old apartment. It is also possible to lease back the old apartment for a few days if you need a bridge of time until everything is cleared for the new place. The attorney/escrow agent should also enter a clause indicating that the closing for the new place is contingent upon closing the old place. These type transactions happen every day and again, any agent worth getting paid should be able to direct you.
Also, it's probably too late now, but you should know that your agent's commission is negotiable and you should not feel obligated or pressured to work with an agent who is not working for you. Finally, make sure the agent in each transaction is actually
your agent and not a actually representing the other party. There are disclosures regarding this that are often misunderstood or overlooked as part of the transaction and one party may not be represented to the utmost.
Good luck!