Skip to main content

The code should be simplified since this is a basic example and it should be clear and simple. You have two variables that aren't actually needed:

  • newNode: when inserting smaller than the first.

  • prevTmp: when inserting after while. It can be tmpNode.

Just remove them and not bother newcomers with looking why you used those.