단순연결리스트 입력 질문이에요.
이뻐
질문 제목 : 단순연결리스트 입력 질문이에요.질문 요약 :숫자를 입력받아 큐 처럼 입력 순서대로 출력이 되고
삭제 할때는 먼저 입력된 녀석이 삭제 되는 소스를 단순 연결리스트 로 짜봤는데요질문 내용 :
#include stdio.h
#include stdlib.h
typedef struct NODE{
int data;
struct NODE *next;
}node;
node *head,*tail;
void init(){
head=(node*)malloc(sizeof(node));
tail=(node*)malloc(sizeof(node));
head-next=tail;
tail-next=tail;
}
void insert(int input){
node *a,*temp;
temp=head;
a=(node*)malloc(sizeof(node));
a-data=input;
temp-next=a;
a-next=tail;
}
void del(){
node *a,*b;
a=head;
b=head-next;
if(a==tail){
printf(There is no data \n);
}
else {
b-next=a-next;
}
}
void print(node *temp){
temp=head;
while(temp!=tail){
printf(%4d \n,temp-data);
temp=temp-next;
}
}
main(){
int n,input;
init();
while(1){
printf(input:);
scanf(%d,&n);
if(n==1){
printf(input data:);
scanf(%d,&input);
insert(input);
}
else if(n==2){
del();
}
else if(n==3){
print(head-next);
}
else { break; }
}
} --------------------------------------------------------------
숫자를 입력받아 큐 처럼 입력 순서대로 출력이 되고
삭제 할때는 먼저 입력된 녀석이 삭제 되는 소스를 단순 연결리스트 로 짜봤는데요.
에러는 없는데출력 할때 제대로 나오질 않네요.입력이 제대로 안되는것 같은데어떤식으로 수정을 해야 되는지 궁금해서 올립니다.삭제부분도 문제 없나 봐주시면 고맙겠네요.