Current streak:
0 days
Longest streak:
7 days
Less
More
// Stack class.
#include<bits/stdc++.h>
class Stack {
public:
int i;
int *st;
int size;
Stack(int capacity) {
this->size = capacity;
st = new int[size];
i = -1;
}
void push(int num) {
if(i < size) st[++i] = num;
return;
}
int pop() {
if(i>-1){
int e = st[i--];
return e;
}
return -1;
}
int top() {
if(i>-1) return st[i];
return -1;
}
int isEmpty() {
return (i==-1)?1:0;
}
int isFull() {
return (i==size-1)?1:0;
}
};
It is giving this error
Compilation Error :
Compilation Failed In file included from runner.cpp:9:0: solution.h:7:20: error: expected identifier before numeric constant vector st(10001,-1); ^ solution.h:7:20: error: expected ',' or '...' before numeric constant solution.h: In constructor 'Stack::Stack(int)': solution.h:10:9: error: '((Stack*)this)->Stack::st' does not have class type this->st.resize(capacity,-1); ^ solution.h: In member function 'void Stack::push(int)': solution.h:16:44: error: invalid types '[int]' for array subscript if(this->isize) this->st[++i] = num; ^ solution.h: In member function 'int Stack::pop()': solution.h:22:33: error: invalid types '[int]' for array subscript