Starting from the end of your question:
Quote:
is sorting and traversing same thing ?
No.
Sorting is the process of ordering nodes so they are in a particular sequence. If you have four nodes:
4 7 3 1
Then sorted they would become:
1 3 4 7
Or
7 4 3 1
If sorted in descending order.
Traversing is the simpler process of "walking through" each node from the head to the tail visiting each node in turn but not changing the content or position of any.
Going back to your "main" problem: We don't know what error you are experiencing, but fixing it is actually part of your assignment.
So use the debugger and follow through what your code is doing.
This is part of your homework, and getting the code to work correctly is part of the task: indeed, it's often the bit that is most interesting and time consuming!
So put a breakpoint on the first line of the function, and step through the code working out in advance what should be happening. Compare that with what did happen and when they don't match you will start to get an idea as to why. You can use the debugger to look at variable contents, as well as stepping through your code line-by-line, and for some systems you can even edit the code while it is running!
But we don't know what system and IDE you are using, so we can't give explicit instructions. Google for "debugger" and the name of your compilation system and you should find at least basic instructions on how to use it.