#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 reverse(node* temp){
if(temp->next==NULL){
head=temp;
return;
}
reverse(temp->next);
node*cur=temp->next;
cur->next=temp;
temp->next=NULL;
}
void print(){
node *temp=head;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
int main() {
head=NULL;
int n;
cin>>n;
for(int i=0;i<n;i++){
int x;
cin>>x;
insert(x);
}
reverse(head);
print();
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: