注册 登录
编程论坛 C图形专区

请高手帮忙!!关于栈的

shxxz 发布于 2010-04-21 17:26, 489 次点击
#include "stdio.h"
#define max  100
struct stack
{
    int data[max];
    int top;
};
void init(struct stack *p)
{
    p->top=-1;
}
void push(struct stack *q,int i)
{
    if(q->top==max-1)
    printf("strack is full\n");
    else q->top++;
    q->data[q->top]=i;
}
int pop(struct stack *h)
{  return (h->data[h->top--]);
    }
void main()
{
   struct  stack *s;
   int a ;
    init(s);
    push(s,4);
    push(s,3);
    push(s,2);
    while(1)
    {
        if(s->top==-1)break;
        printf("%d  ",  (a=pop(s)));
    }
    getchar();
}搞了好久了,还是无法运行
2 回复
#2
横空出世2010-04-24 02:31
你这样就能运行么 main函数都没老大
#3
横空出世2010-04-24 02:32
发错了
1