This is a kind of sorting algorithm that appears in some books of card tricks. Or is it a searching algorithm? It was also a programming task that was in an AQA GCSE Computer Science specimen paper, so I've made a Python version as well.
Sorting and searching really go together to help us find things. A binary search algorithm relies on the items being sorted, for example. Spending time sorting reduces the time you need to spend searching, but it might not always be as important. If you have ten books on your bookshelf then it might not be worth your time sorting them because a search will be simple. If you have 1000 books in a library, then it will be worth sorting them as a search through a larger number of books would be very time-consuming.
If you want to do the trick with actual cards the follow this algorithm: