#include <stdio.h>
#include <stdlib.h>

struct node
{
 int data;
 struct node *link; //1.자기 자신을 저장할수 있는 포인터
 
};

void input_node(struct node **root,int data) //**node안에는 root가 가지고있는 주소,data는 값
{
 struct node *tmp; //동적할당할 포인터 변수
 struct node *search = *root; //널값을 찾아줄 변수
 tmp = (struct node *)malloc(sizeof(struct node) * 1); //*1은 1개만 만든다는거
 tmp->data = data;
 tmp->link = NULL;


 if(*root == NULL) //root 에 주소가없고 null경우
 {
  *root = tmp; // root에 tmp를 넣는다
 }
 else
 {
  while(1)
  {
   if(search->link == NULL) // 만약 search가 link를 찾았을때 null이면
   {
    search->link = tmp; // link에 tmp를 덮어씌운다 (다음 노드와 연결)
    break;
   }
   search = search->link;
  }
 }
}

void output_node(struct node root)
{
 while(1)
 {
  if(root->link == NULL)
  {
   break;
  }
  else
  {
   printf("%s\n",root->link);
  }

  
 }
}


int main()
{
 struct node *root = NULL; //2.노드 주소를 알고있을 포인터 변수 생성
 int i;       // 아무것도 없는 상태라 NULL값
   
 input_node(&root,1);   //3-2.노드 생성함수 만듬
         //3-2.1은 처음 노드가 받는 값
 input_node(&root,2);
 input_node(&root,3);
 input_node(&root,4);


 output_node(root); //data값 출력
 root = root->link;
 

 


 return 0;


 

}


주석 빠진데있으면 주석도 달아주고

주석 오류있으면 주석 수정좀해주라.. 제발..

그리고 위에 아직 수정할게 많은것같은데

data 1 ,2 ,3 ,4 입력된거 출력하려면 어떻게해야되 ?

output_node 라는 함수 선언하고

그걸로 출력해야하는것같은데 도통 모르겠어..