Linked list insert at head

code not working

#include
using namespace std;
class node
//creating anode clas which consistof a constructor which furthrt consist of data
// and next pointer
{
public:
int data;
node* next;
node(int d)

{
data=d;
next = NULL;
}

};
void insertathead(node*&head,int data)
{
node* n=new node(data);
n->next=head;
head =n;
}
void printlist(node* head)
{
node* temp=head;
while(temp!=NULL);
{
cout<data<<"->";
temp=temp->next;
}
}
int main()
{
node*head= NULL;
insertathead(head,1);
insertathead(head,2);
insertathead(head,3);
insertathead(head,4);
printlist(head);
}

@avnoorsingh488 you are writing, cout<data<<"->";
you should write cout<data<<" ";
If this resolves your doubt mark it as resolved.

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.