Exercicio 4

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

typedef struct pais{
    char nome[15];
    int casos;
    int recuperados;
    struct pais *seguinte;
}PAIS;

PAIS* inserirInicio(PAIS* inicio, char nome[], int C, int R){
    // criando nó
    PAIS* novo = (PAIS*) malloc(sizeof(PAIS));
    if(novo != NULL){
        strcpy(novo->nome, nome);
        novo->casos = C;
        novo->recuperados = R;
        novo->seguinte = NULL; // IMPORTANTE
    }
    // inserindo nó, no inicio
    if(novo == NULL) return inicio;
    if(inicio == NULL) return novo;

    novo->seguinte = inicio;
    return novo;
}

PAIS* inserirFinal(PAIS* inicio, char nome[], int C, int R){
    // criando nó
    PAIS* novo = (PAIS*) malloc(sizeof(PAIS));
    if(novo != NULL){
        strcpy(novo->nome, nome);
        novo->casos = C;
        novo->recuperados = R;
        novo->seguinte = NULL; // IMPORTANTE
    }

    // Inserir no final
    PAIS* aux = inicio;

    while(aux->seguinte != NULL){
        aux = aux->seguinte;
    }

    aux->seguinte = novo;

    return inicio;

}


void mostrar(PAIS* inicio){
    if(inicio == NULL) return;

    while(inicio != NULL){

        if(inicio->casos > 3000){
            printf("Nome: %s\n", inicio->nome);
            printf("Número de casos: %d\n", inicio->casos);
            printf("Casos Recuperados: %d\n\n", inicio->recuperados);
        }
        inicio = inicio->seguinte;
    }
}


PAIS* removerPais(PAIS* inicio, char nome[]){
    if(inicio == NULL) return inicio;

    PAIS* aux = inicio;
    PAIS* anterior = inicio;

    while(aux != NULL){
        if( strcmp(aux->nome, nome)==0 ){
            anterior->seguinte = aux->seguinte;
            free(aux);
        }
        anterior = aux;
        aux = aux->seguinte;
    }
    return inicio;
}


int main()
{
    PAIS* paises = NULL;
}