栈的常用操作函数

栈的常用操作函数
以下是我的代码:
#include < stdio.h >
const   long  maxn = 1007 ;
typedef 
struct
{
    
long  top,count,item[maxn];
}stack;
void  clear(stack  & q)
{
    q.count
= 0 ;
    q.top
=- 1 ;
}
bool  empty(stack  & q)
{
    
return  (q.count == 0 );
}
void  push(stack  & q, long  x)
{
    q.top
++ ;
    q.item[q.top]
= x;
    q.count
++ ;
}
void  pop(stack  & q, long   & x)
{
    x
= q.item[q.top];
    q.top
-- ;
    q.count
-- ;
}
int  main()
{
    stack s;clear(s);
    
for ( long  i = 1 ;i <= 10 ;i ++ ) push(s,i);
    
while ( ! empty(s))
    {
       
long  x;
       pop(s,x);
       printf(
" %ld\n " ,x);
    }
    getchar();
return   0 ;
}


你可能感兴趣的:(栈的常用操作函数)