Skip to main content

Posts

Showing posts from May, 2021

Creating multiple stacks using vector with templates in C++

   Problem statement is to create a set of stacks that acts like a pile of plates. Pile of plates can withstand certain height. When it can't withstand we have to create a new set. Implement similar behavior in the code for stack. Use template to implement type independent stack. #include <iostream> #include "vector" #include "string" using namespace std; template<typename a> class setofStacks{     vector<a> setofStacks;     int sizeofEachStack;   public:     void push(a value);     a pop();     a popAt(int index); }; template<typename a> void setofStacks<a>::push(a value){     setofStacks.push_back(value); } template<typename a> a setofStacks<a>::pop(){     a val = setofStacks.back();     setofStacks.pop_back();     return val; } template<typename a> a setofStacks<a>::popAt(int inde...