Home > Back-end >  The realization of the simple stack array
The realization of the simple stack array

Time:09-22

Use an array to realize the stack, the empty too, top, push, pop, the size of these functions;

Input: the first line number input instructions (what to input the total instruction), the second line start typing instructions

On the left side of the sample input, on the right side of the sample output


Local vs operation is no problem, then the school system is uploaded to the topic always run - error, no error,

Ta before because the array is set too small, so from 100 to 10001, but still error run - error



Because is the first time in this web page online sentence system, don't know where is wrong,

I also want to ask next: do you have any other way of cin
to read input?

It is a school to online system environment:
OS: Ubuntu 18.04 (64 - bit)
GCC (Ubuntu 7.3.0-16 ubuntu3) 7.3.0


Code:
 
# include
# include
using namespace std;

The class Array_Stack {
Public:
Int * Stack;
int capacity;//the SIZE
int t;//top

Array_Stack (int) capacity {
This - & gt; Capacity=capacity;
This - & gt; Stack=new int [capacity].
This - & gt; T=1;

}
~ Array_Stack () {
Delete the Stack;
}
{int size ()
Return t + 1;
}

Bool empty () {

If (t==1) {
return true;
}
The else {
return false;
}
}

Int top () {
If (empty ()) {
return -1;
}
The else {
The return Stack [t];
}
}

Void push (int) e {
If (t==capacity - 1) {

}
The else {
Stack [+ + t]=e;

}
}

Int the pop () {
If (empty ()) {
return -1;
}
The else {

The return Stack [t -];
}
}
};
Int main () {

Array_Stack a. (10001);


String STR.
String arr [2];
int index=0;

Int M;
Cin & gt;> M;

For (int n=0; N & lt; M; N++) {

While (cin & gt;> STR) {
Arr [index++]=STR;
Char ch=getchar ();
If (ch=='\ n') break;

}

If (arr [0]=="empty") {


If (A.e mpty ()) {
cout <"1" & lt; }
The else {
cout <"0" & lt; }

} the if (arr [0]=="push") {

Amy polumbo ush (atoi (arr. [1] c_str ()));


} the if (arr [0]=="size") {

cout }
If (arr [0]=="pop") {

cout }
If (arr [0]=="top") {
cout
}
Cin. The clear ();
The index=0;
}


return 0;
}

CodePudding user response:

And then if I put inside the main function is a pile of input code comments, upload it, it is not the run - error; Become the Result: no - output

Does this mean that there was a problem with this part of the code is I entered?

For the first time contact the online evaluation system...
  • Related