I am not giving you nay suggestion about the logic but what i fell dificult in
your code is the naming convention like temp1 or temp2 they should me more close
to the concept like i can guss that they are temp variable but nothing else for
what purpose they'll be used and try to make expressions more simple like one u
wrote is quite complex it will save u to make more variables like storage but
increase the complexity.
This is what i wanna say to u please don't mind but being a student a person
should learn these things too.