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;
}