All code snippets posted on Stack Overflow are posted under Creative Commons licence 3.0.
Share — copy and redistribute the material in any medium or format
Adapt — remix, transform, and build upon the material
for any purpose, even commercially. The licensor cannot revoke these freedoms as long as you follow the license terms.
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
So answering your question, it was plagiarism, as the other student must give the remark, that the author of that code is you.
If you didn't post the whole code it would be more complicated because general patterns are not protected by author's law. What I mean, is that a solution of a problem which is a general pattern doesn't need to be remarked as it's not protected, but if you show code which has some business logic, this makes it author's law protected.
According to Wikipedia:
Plagiarism is the "wrongful appropriation" and "stealing and publication" of another author's "language, thoughts, ideas, or expressions" and the representation of them as one's own original work. The idea remains problematic with unclear definitions and unclear rules.