心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
以下是我的代码:
#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;
}


posted on 2010-01-21 22:39 lee1r 阅读(342) 评论(0)  编辑 收藏 引用 所属分类: 算法与数据结构

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理