Wikipedia provides a simple pseudo-code that demonstrates the concept, besides the fact that I suggest trying to implement it, and then come back if you have any difficulties.
My experience taught me that I never learned anything as well as when I first fought with him, asking for help, when you started, everything is fine, but you need to get a code to prove to yourself that you really understand space, otherwise you just finish cutting and pasting.
Lazarus
source share