Home > Back-end >  Data structure problem
Data structure problem

Time:12-03

1. The sequence as shown below, the definition of a stack initialization, the stack pointer top=1. The complete element stack operation,
# define StackSize 10//the number of storage elements in the stack
Typedef char DataType.
Typedef struct
{
DataType date [StackSize];
Int top;//the stack pointer
}
|
//out of the stack, stack element values through the parameter item return
Pop (Seqstack * S, DataType is int * item)
How to do this?

CodePudding user response:

If (top<0 | | top> StackSize=1)
return 0;
The else
Copy (item, data [top -]);
return 1;

CodePudding user response:

Actually out into the stack these use pointer is relatively good do
Typedef struct {
Int * base;
Int * top;
Int stacksize;
} sqstack;
Int initstack (sqatack & amp; S) {
S.b ase=(int *) malloc (stackinitsize * the size of (int));
if(! S.b ase)
return 1;
S.t op=s.b ase;
S.s tacksize=stackinitsize;
return 0;
}

CodePudding user response:

 if (top<0 | | top> StackSize=1) 
return -1;
* item=data [top --];
return 0;
  • Related