#include<bits/stdc++.h>
using namespace std;
struct node{
int data;
node* next;
};
struct node *head;
void insert(int x){
node* temp=new node();
temp->data=x;
temp->next=head;
head=temp;
}
void print(){
node* temp1=head;
while(temp1!=NULL){
cout<<temp1->data<<" ";
temp1=temp1->next;
}
cout<<endl;
}
int main()
{
head=NULL;
int n;
cin>>n;
for(int i=0;i<n;i++){
int x;
cin>>x;
insert(x);
print();
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: