Template class stack implementation with linked memory blocks