techInterview Discussion |
||
|
A part of techInterview.org: answers to technical interview questions.
Your host: Michael Pryor |
I was reading the book, "Find the bug" by Adam Barr.
An interesting concept, where you are shown code and you have to find bugs in it. Here is one in C: /* Selection Sort */ void sort (int a [] , int n /*length*/) { int current, j, lowestindex, temp; for (current = 0; current < n -1; current++) { lowestindex = current; for (j = current+1; j < n; j++) { if (a[j] < a[current]) { lowestindex = j; } } /* inner for */ if (lowestindex != current) { temp = a[current]; a[current] = a[lowestindex]; a[lowestindex] = tmp; } } /* outer for*/ }
Myopic Thursday, March 05, 2009
int n /*length*/ should be int length
but then I'm one of those IfYouFeelTheNeedToWriteACommentTryToRefactorInstead guys ;) Thursday, March 12, 2009 |
|
Powered by FogBugz


