This is called swapping and is a key step in a lot of programming algorithms.

Here's how the algorithm looks like when written in a programming language called Python.

Don't worry about the code, we'll build this step by step in the next chapter.