should I quit teaching?
Maybe, due the fact:
I couldn't change my attitude. Now, I think that male students might have noticed this and they may make complaints against me to the principal.
Ans: Quit is not a solution. If you do not fix your attitude you can make the situation equally bad (i.e., people complaining to the principle, as mentioned in the comments) in other professions too. However, if you start fixing yourself from now onward, things can easily get right even in the teaching.
So what changes can I make? While teaching how should I give justice equally to both female and male students equally?
If this all is due to opposite gender attraction overwhelming you (as I understood):
The problem is that while teaching I have soft corner towards female students. I don't understand whether it is due to opposite gender attraction or due to female students asking more doubts than male students. I help female students more than male students.
While, you know (but you can't help yourself):
I know that it is against moral ethics of teacher's profession.
And, you've mentioned "unmarried" in the following (if you mean this as one of the factors deforming your attitude):
I am 27 years old unmarried male teacher. I have been a teacher (lecturer) for the last 6 months in an Engineering institution. My students are 4 to 5 years younger than me.
(while being the lecture seems to be a new chapter in your life)
I would suggest you to try to remove "un" ASAP.
Try to get tharapies that would help you control yourself getting into such situation.
Left unchecked may lead to serious implications on your professional life at least.