morning coding challenge selection sort in c
Thu, May 20, 2010
It’s always good to start the day with some code. So I was overjoyed when I read the latest challenge at The Reinvigorated Programmer to create a Selection Sort in any language you want. The only proviso was you couldn’t test it first. i.e. no TDD, no tests, just thinking about the problem. You right the code, think, write some more, think some more, code, think, code think and so on and when you’re confident you’re finished, you run the program and see if it works.
I chose to write it in C for added spice as I’m just ramping up the C/C++ development with iGorm and mod_guanxi and here’s the code. After I ran it for the first time and it worked perfectly, I changed the array a few times to test edge conditions and it worked perfectly each time. It just replace the first element with the lowest on each pass and shuffles the rest up and if that doesn’t match, it shuffles the others down. Glad to see the old grey matter is still working. It’s available as a gist here.