0

I'm pretty new to coding, could anyone please help me initialize a user define array in class stack. i have referred material online but don't know what needs to be done still...

this is a program to implement stack using array.

#include <iostream>
using namespace std;

class stack
{
    public:
    int stack[len], len, top=-1; // var len will store user defined value for array size
    
    bool isEmpty()
    {
        if(top<=-1)
            return 1;
        else
            return 0;

    }
    bool isFull()
    {
           if(top>=len-1)
                return 1;
            else
                return 0;

    }
// other push pop stackTop and display functions;
};
int main()
{
   int ch, val;
         stack s1;
        cout<<"Enter the stack length: ";
            cin>>len; 

// using do while for menu-driven prg to seek the stack operations 
return 0;
}
potato
  • 7
  • 2
  • In C++ the size of all arrays everywhere must be known at compile time, C++ simply does not work this way. You'll need to use `std::vector`, that's what it's for. See your C++ textbook for more information and examples of using `std::vector` to implement arrays of varying sizes. – Sam Varshavchik Mar 28 '22 at 01:13

0 Answers0