
#include <iostream>

using namespace std;
using std::cout;
using std::endl;

struct node{
	int x;
	node *next;
};

struct node *Head;

void AddRoot(struct node *Head,int n){
	Head = new node;
	Head->x=n;
	Head->next=NULL;
}

void DestroyList(struct node **Source){
	struct node *Temp;

	while(*Source){
		Temp= *Source;
		*Source = Temp->next;
		delete Temp;
	}
}

void AddNode(struct node *Head, int n){
	node *NewNode = new node;
	NewNode->x=n;
	NewNode->next=NULL;

	node *cur = Head;

	while(cur){
		if(cur->next == NULL){
			cur->next=NewNode;
			//add new node
			return;
		}
		cur=cur->next;
	}
}

void AddItem(int x, bool IsHead = false){
	if(IsHead){
		AddRoot(Head,x);
	}
	else{
		AddNode(Head,x);
	}
}

int GetItem(int index){
	int temp = 0;
	int x = 0;
	node *list = Head;

	while(list){
		if(x==index){
			temp = list->x;
			break;
		}
		list = list->next;
		x++;
	}
	return temp;
}

int FindItem(int item){
	int idx = -1;
	int x = 0;
	node *list = Head;

	while(list){
		if(list->x==item){
			idx = x;
			break;
		}
		list = list->next;
		x++;
	}
	return idx;
}

int ItemCount(){
	int x = 0;
	node *list = Head;

	while(list){
		list = list->next;
		x++;
	}
	return x;
}

int main(int argc, char **anvg, char**envp){


	AddItem(10,true);
	AddItem(20);
	AddItem(30);
	AddItem(40);
	AddItem(50);


	cout << ItemCount();



	//Just to keep the console open.
	system("pause");
	return 1;
}