구조체 노드 생성 질문
맑다
2023.04.01
질문 제목 :구조체 노드 생성 질문!
질문 내용 :
#include stdio.h
#include stdlib.h
#include string.h
#include conio.h
int main()
{
typedef struct _list{
int pub_id;
char title[20];
struct _list*next;}LIST;
int i;
LIST *ptr, *head , *tail;
head=tail=NULL;
while(1)
{
if((ptr=(LIST*)malloc(sizeof(LIST)))==NULL)
{
printf(1);
exit(1);
}
printf(제목);
gets(ptr-title);
if(!strcmp(ptr-title,end))
break;
printf(publisher id?);
scanf(%d,&ptr-pub_id);
ptr-next=NULL;
fflush(stdin);
if(head==NULL)
head=tail=ptr;
else
{
head-next=ptr;
head=ptr;
}
}
free(ptr);
ptr=head;
while(ptr)
{
printf(아이디:%d , title: %s \n,ptr-pub_id,ptr-title);
ptr=ptr-next;
}
return 0;
}
지금 빨간부분은 노드를 끝부분부터 생성하는건데
반대로 앞부분부터 생성하는 코드좀 알려주실분!! 부탁 드립니다