Quick actions

cmd+k|ctrl+k

Navigation

Languages

12-1연결리스트(재귀)

Snippet info

Language

C

Visibility

public

Author

reddawn12

Created

2017-05-23T07:19:00Z

Updated

2017-05-23T07:19:00Z

#include <stdio.h>
#include <stdlib.h> // malloc함수(동적할당), free함수(동적해제)
#define EMPTY 0

typedef struct node {
	int data;
	struct node* link;
}General;

General* GetNode() {	//노드를 힙 지역에 만들어주는 함수
	General* newNode = (General *)malloc(sizeof(General));
	newNode->link = EMPTY;
	return newNode;
}
void Insert(General** head, int data) {
	if (*head == EMPTY) {
		General* newNode = GetNode();
		newNode->data = data;
		*head = newNode;
		return;
	}		
	General* tmp = *head;

	if ((*tmp).link == EMPTY) {
		General* newNode = GetNode();
		newNode->data = data;
		(*tmp).link = newNode;
	}
	else {
		tmp = (*tmp).link;
		Insert(head, data);
	}	
}

void main() {	
	General* head = EMPTY;
	Insert(&head, 10);
	Insert(&head, 20);
	Insert(&head, 30);


}
INFO