I will happily stop and chat with you if you demonstrate that it is worth the time and interruption (if I was lost in thought, that will take at least 5-10 minutes to get back to).
If not, I will not let you know. I will just fume, blame and judge you for some time after.
"Hey sorry, I've got some things on my mind right now and can't really talk. Have a nice day though".
That takes less than 10 seconds to say, let's you protect your time and peace of mind, and as a bonus there's no need for fuming, blaming, and judging that the other person won't ever even know about.