Whether you're using it for profit has nothing to do with infringement.
The best thing to do is contact the copyright owners and
ask permission. For this code, the owners appear to be listed at the bottom of
this page.
On the other hand, this code looks very fundamental. See
Copyright Registration for Computer Programs (Circular 61 from the United States Copyright Office), which states, "Copyright protection is not available for ideas, program logic, algorithms, systems, methods, concepts, or layouts."