'Smooth 2d turret rotation accounting for wrapping

I wish to make a turret in a 2d game, which should rotate smoothly to the angle of the mouse. I came up with two solutions but neither are satifactory. The first:

currentRot = targetRot; // Produces snapping + doesn't look realistic

The second, inspired from Smoothly rotate turret and retain accuracy :

if (currentRot < targetRot)
{
    currentRot += 2;
    if(currentRot > targetRot)
    {
        currentRot = targetRot;
    }
}
if (currentRot > targetRot)
{
    currentRot -= 2;
    if(currentRot < targetRot)
    {
        currentRot = targetRot;
    }
}

However, the second approach doesn't rotate in the optimal direction all the time. The code doesn't "know" which way to rotate is shorter. I cannot use libraries, and I think quaternions are overkill, so I'm unsure how to solve this problem. Also, is there a third approach that is simpler/better?

Other info: targetRot is from 0°-360°



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source