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

struct node {
	int value;
	struct node* next;
};
typedef struct node node_t;

node_t* create_linked_list(unsigned int number_of_nodes) {
	node_t* head = NULL;
	
	for (unsigned int i = 1; i < number_of_nodes + 1; ++i) {
		/*
		 * malloc might be necessary so that the node doesn't
		 * get wiped from memory once the for loop is over?
		 * TODO: Find out if that is why it's necessary.
		*/
		node_t* node = malloc(sizeof(node_t));
		node->value = i;
		node->next = head;
		head = node;
	}

	return head;
}

void print_list(node_t* head) {
	node_t* temp = head;
	
	while (temp != NULL) {
		printf("%d - ", temp->value);
		temp = temp->next;
	}

	printf("\n");
}

void clean_list(node_t* head) {
	node_t* current = head;
	
	while (current != NULL) {
		node_t* temp = current;
		current = current->next;
		free(temp);
	}
	
	printf("\nclean_list complete \n");
}

int main(void) {
	node_t* head = create_linked_list(15);
	
	printf("head address at beginning = %p\n", head);
	printf("head value at the beginning = %d\n\n", (*head).value);
	
	print_list(head);
	
	clean_list(head);
	
	printf("\nhead address at the end = %p", head);
	printf("\nhead value at the end = %d", (*head).value);
	
	return 0;
}
