Why it is showing output as 1 and 4->
#include<bits/stdc++.h>
using namespace std;
class node
{
public:
int data;
node *next;
node(int d)
{
data= d;
next= NULL;
}
};
void insertion (node *&head, int data)
{
if(head== NULL);
{
head= new node(data);
return;
}
node * n= new node(data);
n->next= head;
head= n;
}
void print(node * head)
{
while(head!=NULL)
{
cout<data<<"->";
head= head->next;
}
}
int length(node * head)
{
if(head==NULL)
return 0;
int c=1;
while(head->next!=NULL)
{
c++; head= head->next;
}
return c;
}
int main()
{
node * head=NULL;
insertion(head,1);
insertion(head,2);
insertion(head,3);
insertion(head,4);
cout<<length(head)<<endl;
print(head);
}