Wrong answers should be downvoted and not flagged. Posts that do not answer the question at all should be deleted, and if you think a post should be deleted, flag it. Common categories of non-answers include:
- Spam — flag as spam
- Insults, etc. — flag as “rude or offensive”
- Follow-up question, vaguely-related digression, etc. — flag as “not an answer”
- Comment intended on another answer or on the question, and that you think is worth keeping around — flag as “in need of moderator intervention” and explain
- Content-free answer: only contains nonsense, or just a link, etc. — flag as “not an answer” or “very low quality”
- Plagiarism — flag as “in need of moderator intervention” and explain; also edit the post to mention the original source if you can identify it
There are ambiguous categories where it isn't always clear whether to delete (possibly after downvoting) or just downvote. The biggest such category is posts that correctly answer a different question. Whether to keep them around depends on how close they match the question: do it represent a common mistake? can it be adjusted to the actual question? Use your judgement, and possibly discuss the specific case in chat or here on meta.
Another category we get here sometimes is answers that are not about computer science, e.g. a pure code dump as an answer to an algorithm question or a statement (“yes it's true” with no indication of how to prove it or at the very least a reference) to a question asking whether something is true and not explicitly asking how to prove it. We don't have a firm policy on those. We had a discussion about this a long time ago, and I stand by Raphael's statement:
this is a computer science site, so questions and answers should to some extent adhere to the scientific method. For answers, that means they should make only falsifiable claims and back them with solid evidence, which can be a (good) reference, (significant) empirical data or a (clear) formal proof (idea). Any answer that does not provide any of the three is likely to be not useful.
As such answers do not actually help anyone, please flag them for deletion.
The answer you're asking about squarely fit into this category when it was originally posted: pure code dump with no explanation, delete on sight. Now the original poster has edited it to add enough comments that it could count as badly-written pseudocode. I think in this state it does constitute an answer, so I wouldn't delete it single-handedly, but I would downvote it for being presented really badly.
A third category of barely-answers is hint-only answers. We have no consensus on those, and they can be genuinely helpful to the original asker, so as a moderator I don't feel comfortable deleting them if the question is evidently homework. I encourage to downvote and provide a more thorough answer if there isn't one yet.