The following code for creating a linked list runs an infinite loop after entering the no. of numbers.
I thought a lot as to what the mistake might be but could not find a solution. Its maybe a small error that is going unnoticed. Please help!
CODE:
#include<iostream.h>
#include<conio.h>
struct Node {
int data;
Node* link;
};
Node* head;
void Insert(int x);
void Print();
void main()
{
clrscr();
head=NULL;
cout<<"How many numbers";
int n,x;
cin>>n;
for(int i=0; i<n; i++)
{
cout<<"enter no";
cin>>x;
Insert(x);
Print();
}
}
void Insert (int x)
{
Node* temp;
temp= new Node();
temp->data=x;
temp->link=head;
head=temp;
}
void Print()
{
Node* temp=head;
while(temp!=NULL)
{
cout<<"List is:"<<temp->data;
temp=temp->link;
}
cout<<"\n";
}
void main(), andiostream.h.void main, removingclrscr), so that it compiles with yesterdaysclang++, I can't make it go wrong. Exactly what do you do to make it go wrong?