#include <iostream>
using namespace std;
struct Node{
int data;
Node* next=NULL;
};
class list{
Node *head,*tail;
public:
void insert(int data){
Node *node =new Node;
node->data=data;
node->next=NULL;
if(head==NULL){
head=node;
tail=node;
}else{
tail->next=node;
tail=tail->next;
}
}
void show(){
Node *n=head;
while(n->next!=NULL){
cout<<n->data<<" ";
n=n->next;
}
cout<<n->data<<endl;
}
};
int main(){
list x;
int n;
for(int i=0;i<10;i++){
cin>>n;
x.insert(n);
}
x.show();
return 0;
}
the program is compiling perfectly but while running it stops and its not working if i put the insert function in loop only then the problem arises but otherwise it is running fine