They mistake was with the constructor function, it was just an typo. Because of which the head
and tail
pointers were not initializing and when the head
pointer was compared against the nullptr
in the if condition of the addToHead(), program was crashing.
solved template program crashing during execution