๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ C Programming/๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ_๊ฐœ์ • 3ํŒ

[๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ - ๊ฐœ์ • 3ํŒ] 13์žฅ Mini Project ๋ฌธ์ œ ํ’€์ด

by A Lim Han 2023. 1. 31.

# 13์žฅ Mini Project ๋ฌธ์ œ ํ’€์ด

 

 

508p_Mini Project)

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

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

int main()
{
	struct NODE* head_node = (struct NODE*)malloc(sizeof(struct NODE));  //๋จธ๋ฆฌ ๋…ธ๋“œ ์ƒ์„ฑ
	head_node->link = NULL;

        struct NODE* node_1 = (struct NODE*)malloc(sizeof(struct NODE));     //1๋ฒˆ์งธ ๋…ธ๋“œ ์ƒ์„ฑ
	node_1->link = head_node->link;
	node_1->data = 1;
	head_node->link = node_1;

	struct NODE* node_2 = (struct NODE*)malloc(sizeof(struct NODE));     //2๋ฒˆ์งธ ๋…ธ๋“œ ์ƒ์„ฑ
	node_2->link = node_1->link;
	node_2->data = 2;
	node_1->link = node_2;

	struct NODE* node_3 = (struct NODE*)malloc(sizeof(struct NODE));     //2๋ฒˆ์งธ ๋…ธ๋“œ ์ƒ์„ฑ
	node_3->link = node_2->link;
	node_3->data = 3;
	node_2->link = node_3;

	struct NODE* curr = head_node->link;  //์ˆœํšŒ์šฉ ๋…ธ๋“œ ์ƒ์„ฑ
	for (int i = 0; i < 3; i++)
	{
		if (curr != NULL)
		{
			printf("%d๋ฒˆ์งธ ๋…ธ๋“œ์— ์ €์žฅ๋œ ์ •์ˆ˜: %d\n", i + 1, curr->data);
			curr = curr->link;
		}
		else
		{
			break;
		}
	}

	free(head_node);
	free(node_1);
	free(node_2);
	free(node_3);

	return 0;
}