#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;
 }*/
 
//  void print(node* temp){
     
//         if(temp==NULL) return;
//          cout<<temp->data<<" ";
//          print(temp->next);
//  }
 
 void revprint(node* temp){
     
        if(temp==NULL) return;
         revprint(temp->next);
         cout<<temp->data<<" ";
 }
 
int main()
{
    head=NULL;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        insert(x);
    }
        //print(head);
        cout<<endl;
        revprint(head);
    
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: