[알고리즘] : 연결리스트(C)

지환·2022년 1월 28일
0

알고리즘

목록 보기
2/12
post-thumbnail

연결리스트

<코드>


#include <stdio.h>
#include <malloc.h>


struct NODE {
	struct NODE* next;
	int data;
};

int main()
{
	struct NODE* head = malloc(sizeof(struct NODE));
	struct NODE* node1 = malloc(sizeof(struct NODE));
	head->next = node1;
	node1->data = 10;

	struct NODE* node2 = malloc(sizeof(struct NODE));
	node1->next = node2;
	node2->data = 20;
	node2->next = NULL;

	struct NODE* curr = head->next;
	while (curr != NULL)
	{
		printf("%d\n", curr->data);
		curr = curr->next;
	}

	free(node2);
	free(node1);
	free(head);
}

<결과>

profile
아는만큼보인다.

0개의 댓글