C언어 에서 스택짜는 프로그램인데..
책보고 그대로 짜봤는데 에러가 뜨네요 ㅠㅠ
낼 시험인데 일단 이해는 가는데 막 안배운부분도 들어가있어서요 ㅠㅠ 일단 에러고치면 이해라도 해서 할것같은데 도저히
에러부분어떻게 수정해야 될지 모르겠어요 ㅠㅠ
일단 프로그램 부분이구요
===
#include <stdio.h>
#include <stdlib.h>
#define empty 0
#define full 10000
typedef char data;
typedef enum {false,true} boolean;
struct elem{
data d;
struct elem *next;
};
typedef struct elem;
struct stack
{
int cnt;
elem *top;
};
typedef struct stack stack;
boolean empty(const stack *stk);
boolean full(const stack *stk);
void initialize(stack *stk)
{
stk->cnt=0;
stk->top=NULL;
}
void push(data d,stack *stk)
{
elem *p;
p=(elem *)malloc(sizeof(elem));
p ->d = d;
p ->next = stk->top;
stk ->top = p;
stk -> cnt++;
}
data pop(stack *stk)
{
data d;
elem *p;
d=stk ->top -> d;
p=stk ->top;
stk -> top = stk ->top ->next;
stk -> cnt --;
free(p);
return d;
}
data top(stack *stk)
{
return (stk ->top ->d);
}
boolean empty(const stack *stk)
{
return ((boolean) (stk->cnt ==EMPTY));
}
boolean full(const stack *stk)
{
return ((boolean) (stk->cnt ==FULL));
}
}
int main(void)
{
char str[]=\"My name is Joanna Kelly!\";
int i;
stack s;
initialize(&s);
printf(\" In the string: %s\\n\",str);
for(i=0;str[i] !=NULL;++i)
{
if (!full(&s))
{
push(str[i],&s);
printf(\"From the stack: \");
}
while (! empty(&s))
{
putchar(pop(&s));
putchar(NULL);
return 0;
}
}
}
===
=======
제발도와주세요 ㅠㅠ
댓글 0