If i give 1 as size and 1 elemnt it prints "1->"But when I try to give size as 5 and element as 1 2 3 4 5 the compiler doesnt print anything…Kindly help me with this.I am new to linked list concept
using namespace std;
void display();
struct node
{
int data;
struct node* link;
};
struct node* root;
int main()
{
int n;
cin>>n;
struct node* temp;
for(int i=0;i<n;i++)
{
if(root==NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
cin>>temp->data;
temp->link=NULL;
root=temp;
}
else
{
struct node* p;
temp=(struct node *)malloc(sizeof(struct node));
cin>>temp->data;
temp->link=NULL;
root=p;
while(p->link=NULL)
{
p=p->link;
p->link=temp;}}}
display();
return 0 ;}
void display()
{
struct node* temp=root;
while(temp!=NULL)
{
cout<<temp->data<<"->";
temp=temp->link;
}}