If you understand the algorithm, just rewrite the whole thing from scratch without looking at the other code. If you cannot do that, then you don't understand the algorithm used and you are copying...