Plzz tell the error in this program

#include
using namespace std;
class node
{
public:
int data;
node* next;

	//constructor
	node(int d)
	{
		int data=d;
		next=NULL;
	}

};
void insertathead(node*&head,int d)
{
//base case
if(head==NULL)
{
head=new node(d);
return;
}
node n=new node(d);
n->next=head;
head=n;
}
void insertattail(node
&head,int d)
{
//base case
if(head==NULL)
{
insertathead(head,d);
}
else
{
node temp=head;
while(temp!=NULL)
{
temp=temp->next;
}
node
n=new node(d);
temp->next=n;
}

	}
	int length(node *head)
	{
		int l=1;
		while(head!=NULL)
		{
			head=head->next;
			l++;
		}
        return l;
	}
	void insertatmiddle(node* &head,int d,int p)
	{
		//base case
		if(head==NULL)
		{
			insertathead(head,d);
		}
		else if(p>=length(head))
		{
			insertattail(head,d);
		}
	    else
		{
			node *temp=head;
			int j=1;
			while(j<p)
			{
				temp=temp->next;
				j++;
			}
			node*n=new node(d);
			n->next=temp->next;
			temp->next=n;
			
		}
	}
		void print(node *head)
		{
			while(head!=NULL)
			{
				cout<<head->data<<" ,";
				head=head->next;
		
			}
		}

		

	int main()
	{
		node *head=NULL;
		insertathead(head,6);
		insertathead(head,5);
		insertathead(head,3);
		insertathead(head,2);
		insertathead(head,1);
		print(head);
        
		insertattail(head,7);
		insertatmiddle(head,4,4);
		print(head);
		length(head);
		return 0;
	}

Hello @1928214
i have corrected your code and commented the mistakes:


if you have any doubt you can ask here;
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.