Introfor

[data_structure] Linked List 본문

Doing/C&C++

[data_structure] Linked List

YongArtist 2020. 7. 26. 16:07

 

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

typedef struct node{
	int data;
	struct node* next;
} Node;

int main(){

	Node* head = NULL;

	head = (Node*)malloc(sizeof(Node));
	head->data = 1;
	head->next = NULL;

	Node* q = (Node *)malloc(sizeof(Node));
	q->data = 2;
	q->next = NULL;
	head->next = q;

	q = (Node *)malloc(sizeof(Node));
	q->data = 0;
	q->next = head;
	head = q;

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

	return 0;
}

 

'Doing > C&C++' 카테고리의 다른 글

[Recursion] Counting Cells in a Blob  (0) 2020.07.30
Recursion. 미로찾기  (0) 2020.07.28
[Algorithm] sequential Search  (0) 2020.07.01
[C++] Reference  (0) 2020.06.29
[C++] Pair, Vector STL  (0) 2020.06.29
Comments