오류점 잡아주세요 ㅜ
으뜸
질문 제목 : 스택을 연결리스트로 짠건데여...오류좀 잡아주세요질문 내용 :제가 짠 건데요 연결리스트의 아래 표시한 음수부분 을 모두 삭제하는쪽에 문제가 있는거 같은데 어떡해야하나요..
#includestdio.h
#includestdlib.h
#define max 6
typedef struct _node
{
int key;
struct _node *next;
}node;
node *head,*tail;
void init_stacka(void)
{
head =(node*)malloc(sizeof(node));
tail =(node*)malloc(sizeof(node));
head-next=tail;
tail-next=tail;
}
int push(int *stacka,int t)
{
int topa=-1;
node *k;
k =(node*)malloc(sizeof(node));
k-key=t;
k-next=head-next;
head-next=k;
return t;
}
int print_stack1(int *stacka,int topa)
{
node *a;
a=head-next;
printf(\ntop-bottom\n);
for(a;a!=tail;a-next)
{
printf(%3d,a-key);
a=a-next;
}
return 0;
}
int deleteneg(int *stacka,int topa)
{
node *a,*b;
a=head;
b=head-next;
while(b!=tail)
{
if(b-key0)
{
a-next=b-next;
free(b);
}
a=a-next;
b=b-next;
}
return 0;
}
void main()
{
init_stacka();
int stacka[max];
int topa=-1;
push (stacka, 10);
push (stacka, 5);
push (stacka, -3);
push (stacka, 9);
push (stacka, -1);
push (stacka, 8);
print_stack1(stacka,topa);
deleteneg(stacka, topa);
printf_stack1(stacka,topa);
}