Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct aluno {
- char *nome;
- int idade;
- struct aluno *proxAluno;
- } estudante;
- void inserir(estudante **inicio, char *nome, int idade) {
- estudante *novoEstudante;
- novoEstudante = malloc(sizeof(estudante));
- novoEstudante->nome = nome;
- novoEstudante->idade = idade;
- if (*inicio == NULL) {
- novoEstudante->proxAluno = NULL;
- *inicio = novoEstudante;
- } else {
- novoEstudante->proxAluno = *inicio;
- *inicio = novoEstudante;
- }
- }
- void remover(estudante **inicio) {
- estudante *estudanteAtual;
- if (*inicio != NULL) {
- estudanteAtual = *inicio;
- printf("Aluno %s removido!\n", estudanteAtual->nome);
- *inicio = (*inicio)->proxAluno;
- free(estudanteAtual);
- }
- }
- void listar(estudante **inicio) {
- estudante *elementoAtual;
- elementoAtual = *inicio;
- while (elementoAtual != NULL)
- {
- printf("Estudante %s com %d anos\n", elementoAtual->nome, elementoAtual->idade);
- elementoAtual = elementoAtual->proxAluno;
- }
- }
- int main (void) {
- estudante *inicio = NULL;
- char *nome = "Reni";
- int idade = 18;
- inserir(&inicio, nome, idade);
- listar(&inicio);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement