Home > Back-end >  Excuse me, where is the problem, how to modify
Excuse me, where is the problem, how to modify

Time:03-15

#include

using namespace std;
Const int MAX_SIZE=1024;
Struct SeqStack {
The int data [MAX_SIZE];
Int size;
};
//initialize
SeqStack * Init_Stack () {
Auto stack=new SeqStack;
Stack - & gt; Size=0;
for (int i=0; i Stack - & gt; Data [I]=1;
}
The return stack.
}
//pressure stack
Void Push_Stack (SeqStack * stack, int val) {
If (stack==nullptr)
return;
If (stack - & gt; Size==MAX_SIZE)
return;
Stack - & gt; Data [stack - & gt; size]=val;
Stack - & gt; size++;
}
//return stack element
Int Top_Stack (SeqStack * stack) {
If (stack==nullptr)
The return - 1;
If (stack - & gt; Size==0)
return -1;
The return stack - & gt; Data [stack - & gt; size - 1].
}
//the stack
Void Pop_Stack (SeqStack * stack) {
If (stack==nullptr)
return;
If (stack - & gt; Size==0)
return;
Stack - & gt; Size -;
}
//determine whether empty
Int IsEmpty (SeqStack * stack) {
If (stack - & gt; Size==0)
return 1;
If (stack==nullptr)
return -1;
return 0;
}
//returns the number of elements in the stack
Int Size_Stack (SeqStack * stack) {
If (stack==nullptr)
return -1;
The return stack - & gt; The size;
}
//to empty stack
Void Clean_Stack (SeqStack * stack) {
If (stack==nullptr)
return;
Stack - & gt; Size=0;
}
//destruction of stack
Void Free_Stack (SeqStack * stack) {
If (stack==nullptr)

return;
Free (stack);
}

CodePudding user response:

The size is the size? The index minus 1
  • Related