#include <stdio.h>
#include <stdlib.h>

typedef struct Node{
    int data;
    struct Node* next;
}Node;

struct Node* top = NULL; 

Node* alloc_node(int e){
    Node* p = (Node*)malloc(sizeof(Node));
    p->data = e;
    p->next = NULL;
    return p;
}

int is_empty(){
    if(top == NULL){
        return 1;
    }
    else{
        return 0;
    }
}

void push(int e){
    Node* p = alloc_node(e);
    if(is_empty()){
        top = p;
    }
    else{
        p->next = top;
        top = p;
    }
}

void reverse(Node* t){
    if(t == NULL){
        return;
    }
    reverse(t->next);
    printf("%d ", t->data);
}

void print_recur(){
    if(is_empty()){
        printf("Empty\n");
        exit(0);
    }
    else{
        reverse(top);
    }
}

int main(void){

    int N;
    scanf("%d", &N);

    int a;
    for(int i = 0 ; i < N ; i++){
        scanf("%d", &a);
        push(a);
    }

    print_recur();

    return 0;
}









Embed on website

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