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

Time:09-23

#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
reference 1/f, Simple, Soft reply:
what is it? Compile errors or run-time error

Compile error,

CodePudding user response:

Template
Friend ostream& Operator<(ostream& Out, seqstack & B);

CodePudding user response:

references in 4th floor, the truth is more important than right or wrong response:
template
Friend ostream& Operator<(ostream& Out, seqstack & B);

Or can't ah, or there is something wrong with the compilation,

CodePudding user response:

 # include & lt; Iostream> 
#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 & gt;> a;
(* this). Push (a);
N -;
Top++;
}
}
Bool pop (T& X) {
If (top==1) return false.
The else {
X=elements [top --];
return true;
}
}
Template
Friend ostream& Operator<(ostream& Out, seqstack & B);
};
Template
Ostream& Operator<(ostream& Out, seqstack & B) {
The out & lt; <"Top=" & lt; int i;
for (i=0; i <=b.t op; I++)
The out & lt; Return 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 & gt;> n;
Seqstack S (50);
S.i nput (n);
int a;
Supachai panitchpakdi op (a);
Int m=10;
Supachai panitchpakdi ush (m);
Cout & lt; return 0;
}

Find their own different
  • Related