[안녕하세요^^]스택인데요, 사가제가 안되요...왜 그렇죠???
초월
안녕하세요...오늘 처음 가입하고 바로 질문하네요...ㅎㅎㅎ
앞으로 사이트 활동 열심히 하겠습니다. ^ㅡ^
아래는 스택 간단하게 만든건데요,,, 이해가 안되는게, 삭제 명령만 떨어지면, 종료가 되요...왜 그런가요??
또 여기서 struct 포인터로 두개의 포인터를 사용하였는데요, 왜 두개를 사용해야 하나요?하나도 될꺼깥은데...
그부분에 대해 설명 부탁드립니다. =ㅁ=;;
#include stdio.h
#include stdlib.h
struct stack{
int data;
struct stack *next;
};
void push(struct stack ** top, int _data);
int pop(struct stack ** top);
void display(struct stack *top);
void menu();
void main()
{
int a=0, data1=0;
struct stack *top=null;
menu();
scanf(%d,&a);
while(a!=4)
{
switch(a)
{
case 1 : printf(input : );
scanf(%d,&data1);
push(&top,data1);
break;
case 2 : if(top==null) printf(no data!);
else{
printf(%d delete,pop(&top));
}
break;
case 3 : display(top);
break;
}
menu();
scanf(%d,&a);
}
}
void menu()
{
printf(push : 1, pop : 2, display : 3, end : 4\n);
}
void push(struct stack ** top, int data1)
{
struct stack * tmp;
tmp=(struct stack*)malloc(sizeof(struct stack));
tmp-data=data1;
tmp-next=(*top);
(*top)=tmp;
}
int pop(struct stack **top)
{
struct stack *temp;
int del=0;
temp=(*top);
del=(*top)-data;
(*top)=(*top)-next;
free(temp);
return del;
}
void display(struct stack *top)
{
if(top==null)
printf(no data\n);
else{
while(top != null)
{
printf(%d,top-data);
top=top-next;
}
printf(\n);
}
}
-
푸른나무
=ㅁ=;;; 여기에 하는건지 알았어요...
-
갅지돋는슬아
질문은 질문게시판에 ;;