/* 接口函数定义 */
int Initialize_S (Stack * const pstack, const int capacity)
{
if (capacity <= 0)
return 0 ;
*pstack = (struct stack *) malloc (sizeof (struct stack)) ;
if (NULL == *pstack)
return 0 ;
(*pstack) -> array = (Stack_Item *) malloc (sizeof (Stack_Item) * capacity) ;
if (NULL == (*pstack) -> array)
{
free (*pstack) ;
return 0 ;
}
(*pstack) -> capacity = capacity ;
(*pstack) -> top = EMPTY_TOP ;
return 1 ;
}
int IsEmpty_S (const Stack * const pstack)
{
return EMPTY_TOP == (*pstack) -> top ;
}
int IsFull_S (const Stack * const pstack)
{
return (*pstack) -> top + 2 > (*pstack) -> capacity - 1 ;
}
int Push_S (const Stack * const pstack, const Stack_Item st1, const Stack_Item st2)
{
if (IsFull_S (pstack))
return 0 ;
(*pstack) -> array[++(*pstack) -> top] = st1 ;
(*pstack) -> array[++(*pstack) -> top] = st2 ;
return 1 ;
}
int Pop_S (const Stack * const pstack, Stack_Item * const pst1, Stack_Item * const pst2)
{
if (IsEmpty_S (pstack))
return 0 ;
*pst2 = (*pstack) -> array[(*pstack) -> top--] ;
*pst1 = (*pstack) -> array[(*pstack) -> top--] ;
return 1 ;
}
void Release_S (const Stack * const pstack)
{
free ((*pstack) -> array) ;
free (*pstack) ;
}