Skip to content
๐Ÿ” Swapping with Temporary Variables

๐Ÿ” Swapping with Temporary Variables

Imagine 2 boxes with things inside it

We cant move the items inside that box into the other box directly, because each box is designed to hold only 1 thing

But if we just throw one of them aside to allow space for the other to come in, we might lose it as it does not have a known space to be thrown out of

Thus we will need a separate box to store this thing temporarily, so we can move the other into this box

Then the item inside the temporary box can be then shifted into the other box that is now empty

Last updated on