Fixing your code for you will teach you nothing. You'll go from having code that you don't know why it doesn't work to code that you don't know why it does work. This entirely defeats the point of homework.
As some of the comments say, you need to learn how to inspect and debug code, using debugging tools or even just printing a load of status output as you go, in order to understand what the code is actually doing.
This is a far more important exercise to the discipline of programming than the basic data-structure stuff (that in reality you're rarely ever going to have to write as it'll come out of a library).