Created
May 1, 2016 00:28
-
-
Save Luanr/0b1f303baafcc05b6daf68d6d0d0f862 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define N 500 | |
struct pessoa { | |
char nome[50]; | |
double salario; | |
double altura; | |
}; | |
typedef struct pessoa Pessoa; | |
struct cel{ | |
Pessoa conteudo; | |
struct cel *seguinte; | |
}; | |
typedef struct cel celula; | |
void insere(celula * cel, Pessoa humano); | |
void remover(celula *cel); | |
void imprimir(celula *cel); | |
/*typedef celula *lista;*/ | |
int main() { | |
celula * lst; | |
Pessoa cara; | |
celula * nova; | |
lst = NULL; | |
strcpy(cara.nome, "Luan"); | |
imprimir(lst); | |
insere(lst, cara); | |
nova = malloc(sizeof(celula)); | |
return 0; | |
} | |
void imprimir(celula *cel) { | |
celula * aux; | |
if(cel = NULL) { | |
printf("Lista vazia!"); | |
return; | |
} | |
for(aux = cel-> seguinte; aux != NULL; aux = aux ->seguinte) { | |
printf("%s \n", aux -> conteudo.nome); | |
} | |
} | |
void insere(celula * cel, Pessoa humano) { | |
celula * nova; | |
nova = (celula *) malloc(sizeof(celula)); | |
nova-> conteudo = humano; | |
if(cel) { | |
nova-> seguinte = cel->seguinte; | |
cel -> seguinte = nova; | |
} else { | |
cel = nova; | |
} | |
} | |
void remover(celula *cel) { | |
celula * lixo; | |
lixo = cel -> seguinte; | |
cel -> seguinte = lixo ->seguinte; | |
free(lixo); | |
} | |
celula * busca(celula *cel, char nome[]) { | |
while(cel != NULL && cel->conteudo.nome != nome) { | |
cel = cel -> seguinte; | |
} | |
return cel; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment