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

typedef struct noLista {
    int info;
    struct noLista *prox;
} Elemento;

Elemento* criarNovo(int Caractere);
Elemento* Push(Elemento *Topo, int Caractere);
Elemento* Pop(Elemento *Topo);
Elemento* Top(Elemento *Topo);

int main () {
    int Dados, i, op;
    Elemento *Pilha = NULL, *aux, *Pilha2 = NULL;

    do {
        printf("1 - Adicionar elemento\n");
        printf("2 - Remover elemento\n");
        printf("0 - Encerrar\n\n");

        printf("Opcao: ");
        scanf("%d", &op);

        switch(op) {
        case 1:
            printf("Digite um inteiro: ");
            scanf("%d", &Dados);

            Pilha = Push(Pilha, Dados);
            printf("Elemento adicionado\n\n");
            break;

        case 2:
            if (Top(Pilha2) == NULL){
                while (Top(Pilha) != NULL){
                    int removido = Top(Pilha)->info;
                    Pilha = Pop(Pilha);
                    Pilha2 = Push(Pilha2, removido);
                }
            }

            if(Top(Pilha2) != NULL) {
                int removido = Top(Pilha2)->info;
                Pilha2 = Pop(Pilha2);
                printf("Elemento %d removido\n\n", removido);
            } else {
                printf("A pilha esta vazia\n\n");
            }
            break;

        case 3:

            break;

        }
    } while(op!=0);
    return 0;
}

Elemento* criarNovo(int Caractere) {
    Elemento *novo;

    novo = (Elemento*) malloc(sizeof(Elemento));
    novo->info = Caractere;
    novo->prox = NULL;

    return novo;
}

Elemento* Push(Elemento *Topo, int Caractere) {
    Elemento *novo;

    novo = criarNovo(Caractere);

    novo->prox = Topo;
    Topo = novo;
    return Topo;
}

Elemento* Pop(Elemento *Topo) {
    Elemento *aux;

    aux = Topo;
    if(Topo != NULL) {
        Topo = Topo->prox;
        free(aux);
    }
    return Topo;
}

Elemento* Top(Elemento *Topo) {
    return Topo;
}
