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

static List *head = NULL;	// What is this static?

List *listNewNode() {
	return (List *)malloc(sizeof(List));
}
/*List *listInsert(int data) {
	List *node = listNewNode();
	node->data = data;
	if (head == NULL) {
		node->next = head;
		head = node;
	} else {
		List *ptr;
		for (ptr = head; ptr->next != NULL; ptr = ptr->next)
			;
		// ptr points to the last node in the list.
		ptr->next = node;
		node->next = NULL;
		// no update to head.
	}
	return head;
}*/
List *listInsert(int data) {
	List *node = listNewNode();
	node->next = head;
	node->data = data;
	head = node;
	return head;
}
void listNodePrint(List *node) {
	printf("%d\n", node->data);
}
int listPrint() {
	int nnodes = 0;
	for (List *ptr = head; ptr != NULL; ptr = ptr->next, ++nnodes)
		listNodePrint(ptr);
	return nnodes;
}
