Monday, 11 July 2016

Stack as a Template class

Following is the implementation of a stack as a template class.
The most interesting thing to note is the default return of pop in case the stack is empty. It can be written as T(). This is calling the default constructor of the datatype assigned to T. I checked and the default value for int, double, float is 0 and for string is an empty string. This solves so many other problems also :)


























Output:




No comments:

Post a Comment