typedef struct node1* Node;
struct node1{
int num;
Node next;
};
void insert(Node, int);
int main() {
Node head = (Node)malloc(sizeof(struct node1));
for (int i = 1; i <= 5; i++) {
insert(head, i);
}
Node curr = head->next;
while (1) {
printf("%i", curr->num);
curr = curr->next;
}
return 0;
}
void insert(Node head, int data) {
Node list = (Node)malloc(sizeof(struct node1));
if (head == NULL) {
list->num = data;
list->next = list;
head = list;
}
else {
list->num = data;
list->next = head->next;
head->next = list;
}
}
head를 NULL로 선언하고 insert에서 head의 주소를 넘겨줘
.