Problem with that is, you won't know how to come up with the solution in the first place when you see a new problem, which is usually the hardest part. Not the implementation of an algorithm already...
Type: Posts; User: cyberfish
Problem with that is, you won't know how to come up with the solution in the first place when you see a new problem, which is usually the hardest part. Not the implementation of an algorithm already...
Does it actually work? doesn't look like what you described in the first post to me.
*edit*
nvm I see it does. You can save one iteration by making it
for(int i=length-1; i > 1; i--)
...
Please don't write complete code for people. They don't learn much this way.
It's even worse if it's homework.
Almost.
BTW, it's usually not a good idea to use sizeof to determine array length, since it won't work for dynamically allocated arrays or arrays passed into functions (you will just get the size...
Think about how you would do it by hand, then write it as C++ statements (no loop), then try to find a pattern into those statements, and turn them into a loop.