Home >
Back-end > Order of the stack (c), want to know the following code where I went wrong, ask for help
Order of the stack (c), want to know the following code where I went wrong, ask for help
#include
using namespace std;
Const int happens=20;
Template
The class seqstack {
Private:
T * elements;
Int top;
Int Max;
Void overflow ();
Public:
Seqstack (int m) {
Top=1;
Max=m;
T * elements=new T (Max);
}
Void push (T, x) {
If (top==Max - 1) overflow ();
Elements [+ + top]=x;
}
Void input (int n) {
T a;
While (n) {
cin> a;
(* this). Push (a);
N -;
Top++;
}
}
Bool pop (T& X) {
If (top==1) return false.
The else {
X=elements [top --];
return true;
}
}
Friend ostream& Operator<(ostream& Out, seqstack & B);
};
Template
Ostream& Operator<(ostream& Out, seqstack & B) {
Out<& lt;" Top="& lt; int i;
for(i=0; i<=b.t op; I++)
OutReturn the out;
}
Template
Void seqstack : : overflow () {
T * d=new T/Max + happens;
int i;
for(i=0; i<=top; I++) {
[I]=d elements [I];
}
The delete [] elements;
Elements=d;
}
Int main () {
int n;
cin> n;
Seqstack S (50);
S.i nput (n);
int a;
Supachai panitchpakdi op (a);
int m;
Supachai panitchpakdi ush (m);
Coutreturn 0;
} CodePudding user response:
What's the problem? Compile errors or run-time error CodePudding user response:
Compile error, CodePudding user response:
The