I don't see any problem with your code right off. When I run your code and manually set the array to be random-ish values, it works. Is it possible you aren't reading what you think you're reading...