All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
You have done well by being eager to lead a life according to what pleases Allaah The Almighty; and we ask Allaah The Almighty to help you achieve your purpose.
As to the mixed education that is common in most universities, it is the direct cause of much corruption. Moreover, the teacher's asking the students to engage in conversation with each other without differentiation between males and females, increases the danger; and if they are also required to talk to each other in a friendly manner, it would become even worse. Please see Fatwa 87469.
We advise you to try to convince those in charge of that learning institution to separate between males and females, in such a way as to make each gender in an independent class, or, at least, to conduct such conversations between the members of each gender solely. If this is done, all perfect praise be to Allaah, otherwise, guarding your religion should be preferable for you. This means that you should stop studying in that institution, and search for another one which does not have such prohibited things; and we do not think that there is a necessity or a dire need to make it permissible for you to continue that study in such a way that displeases your Lord, and because of which you might lose your religion.
As for the means to remain steadfast on the path of Allaah, see Fataawa 85277 and 84807. As for the way to repentance, see Fataawa 86527 and 87903.
Allaah Knows best.