Question: Hello I am trying to insert a char using stack in c++ and am having trouble running my code. I am not sure what the
Hello I am trying to insert a char using stack in c++ and am having trouble running my code. I am not sure what the issue is so please check and correct my code.
#include
#include
using namespace std;
template
class Stack
{
private:
T *st;
int size;
int top;
public:
Stack(){size=10;top=-1;st=new T[size];}
Stack(int size){this->size=size;top=1;st=new T[this->size];
void push(T x);
T pop();
T peek(int index);
int stacktop();
int isEmpty();
int isFull();
void Display();
};
template
void Stack
{
if(isFull()){
cout<<"Stack Overflow"< } else{ top++; st[top]=x; } } template T Stack if(isEmpty()){ cout<<"Stack Underflow"< } else{ x=st[top]; top--; } return x; } template T Stack { T x=-1; if(top-index+1<0){ cout<<"Invalid Index"< } else{ x=st[top-index+1]; } return x; } template int Stack if(isEmpty()){ return -1; } return st[top]; } template int Stack if(top==size-1){return true;} else{return false;} } template int Stack if(top==-1){return true;} else{return false;} } template void Stack for(int i=top;i>=0;i--){ cout< } cout< } int main(){ Stack stk.push('a'); stk.push('b'); stk.push('c'); stk.push('d'); stk.push('e'); stk.push('f'); stk.display(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
