Home > Back-end >  Why I enter into the elements can only last a stack? Should not be a stack of six different
Why I enter into the elements can only last a stack? Should not be a stack of six different

Time:04-19

#include
#include
# define STACK_INIT_SIZE 100
# define STACKINCREMNT 10
# define OVERFLOW 0
# define the ERROR 0
# define OK 1
Typedef struct {
Int * top;
Int * base;
int stacksize;
} SqStack;
Int InitStack (SqStack & amp; L) {
L.b ase=(int *) malloc (10 * sizeof (int));
if(! L.b ase) exit (OVERFLOW);
L.t op=L.b ase;
L.s tacksize=10;
Return OK; }
Int GetTop (SqStack L, int & amp; E)
{
If (L.b ase==L.t op) return the ERROR;
E=* (L.t op - 1); Return OK;
}
Int a Push (SqStack L, int e)
{
If (L.t op - L.b ase>=L.s tacksize) {
L.b ase=(int *) realloc (L.b ase, (L.s tacksize + STACKINCREMNT) * sizeof (int));
L.t op=L.b ase + L.s tacksize;
L.s tacksize=L.s tacksize + STACKINCREMNT;
}
* (L.t op++)=e;
Return OK;
}
Pop (SqStack is int L, int & amp; E)
{
If (L.t op!=L.b ase)
E=* (L.t op -);
return e;
}
Int main ()
{
Int I, n, m;
SqStack L;
InitStack (L);
for(i=0; i<6; I++) {
The scanf (" % d ", & amp; N);
Push (m, n); }
For (m=0; M<6; M++) {
Pop (m, n);
Printf (" % d \ n ", n); }
}

CodePudding user response:

Reference:
 # include 
#include

# define STACK_INIT_SIZE 100
# define STACKINCREMNT 10
# define OVERFLOW 0
# define the ERROR 0
# define OK 1

Typedef struct {
Int * top;
Int * base;
int stacksize;
} SqStack;

Int InitStack (SqStack & amp; L)
{
L.b ase=(int *) malloc (10 * sizeof (int));
if(! L.b ase) exit (OVERFLOW);
L.t op=L.b ase;
L.s tacksize=10;
Return OK;
}
Int GetTop (SqStack L, int & amp; E)
{
If (L.b ase==L.t op) return the ERROR;
E=* (L.t op - 1);
Return OK;
}
Int a Push (SqStack & amp; Int L, e)//int Push (SqStack L, int e)
{
If (L.t op - L.b ase>=L.s tacksize) {
L.b ase=(int *) realloc (L.b ase, (L.s tacksize + STACKINCREMNT) * sizeof (int));
L.t op=L.b ase + L.s tacksize;
L.s tacksize=L.s tacksize + STACKINCREMNT;
}
* (L.t op++)=e;
Return OK;
}
Int Pop (SqStack & amp; L, int & amp; E)//int Pop (SqStack L, int & amp; E)
{
If (L.t op!=L.b ase)
E=* (-- L.t op);//e=* (L.t op -)
Return OK;//e;
}

Int main ()
{
Int I, n, m;
SqStack L;
InitStack (L);
for(i=0; i<6; I++) {
The scanf (" % d ", & amp; N);
Push (m, n);
}
For (m=0; M<6; M++) {
Pop (m, n);
Printf (" % d \ n ", n);
}

return 0;
}

CodePudding user response:

reference 1st floor QZJHJXJ response:
for reference:
 # include 
#include

# define STACK_INIT_SIZE 100
# define STACKINCREMNT 10
# define OVERFLOW 0
# define the ERROR 0
# define OK 1

Typedef struct {
Int * top;
Int * base;
int stacksize;
} SqStack;

Int InitStack (SqStack & amp; L)
{
L.b ase=(int *) malloc (10 * sizeof (int));
if(! L.b ase) exit (OVERFLOW);
L.t op=L.b ase;
L.s tacksize=10;
Return OK;
}
Int GetTop (SqStack L, int & amp; E)
{
If (L.b ase==L.t op) return the ERROR;
E=* (L.t op - 1);
Return OK;
}
Int a Push (SqStack & amp; Int L, e)//int Push (SqStack L, int e)
{
If (L.t op - L.b ase>=L.s tacksize) {
L.b ase=(int *) realloc (L.b ase, (L.s tacksize + STACKINCREMNT) * sizeof (int));
L.t op=L.b ase + L.s tacksize;
L.s tacksize=L.s tacksize + STACKINCREMNT;
}
* (L.t op++)=e;
Return OK;
}
Int Pop (SqStack & amp; L, int & amp; E)//int Pop (SqStack L, int & amp; E)
{
If (L.t op!=L.b ase)
E=* (-- L.t op);//e=* (L.t op -)
Return OK;//e;
}

Int main ()
{
Int I, n, m;
SqStack L;
InitStack (L);
for(i=0; i<6; I++) {
The scanf (" % d ", & amp; N);
Push (m, n);
}
For (m=0; M<6; M++) {
Pop (m, n);
Printf (" % d \ n ", n);
}

return 0;
}

Thank you, has been solved, did not take address
  • Related