0

I got run-time error for the following code. I am just starting to get familiar with linked list. Can any one point out what's the problem here? thanks

```
#include "stdafx.h"
#include<iostream>
using namespace std;
struct node
{
int data;
node * next;
};
node* buildonetwothree()
{
node* head=NULL;
node* second=NULL;
node* third=NULL;
head->data=1;
head->next=second;
second->data=2;
second->next=third;
third->data=3;
third->next=NULL;
return head;
}
int length(node* head)
{
node* moving=head;
int count=0;
while(moving!=NULL)
{moving=moving->next;
count++;}
return count;
}
void main()
{
node* head=NULL;
head=buildonetwothree();
cout<<length(head);
}
```