Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <string.h>
- #define MAX 10
- struct Pessoa {
- int vetor[MAX],size;
- char str[MAX];
- };
- typedef struct Pessoa pessoa;
- typedef struct Celula {
- pessoa *dados;
- struct Celula *ant;
- struct Celula *prox;
- }cel;
- cel *cria_cel(void)
- {
- cel *c = (cel *) malloc(sizeof(cel));
- if (c!= NULL)
- c->ant = NULL;
- c->prox = NULL;
- return c;
- }
- bool isEmpty(cel *c)
- {
- return (c->prox == NULL);
- }
- bool Push(cel **c,pessoa *p)
- {
- cel *novo = (cel *) malloc(sizeof(cel));
- cel *aux;
- if (novo == NULL)
- {
- fprintf(stderr," erro "); exit( 0 );
- }
- novo->dados = p;
- novo->prox = NULL;
- novo->ant = (*c);
- if (isEmpty(*c)){
- printf("vazia");
- (*c)->prox = novo;
- }else{
- printf("tem");
- aux = (*c)->prox;
- while(aux->prox != NULL){
- aux = aux->prox;
- }
- aux->prox = novo;
- aux->ant = aux;
- }
- return true;
- }
- void imprime(cel **c)
- {
- cel *pointer;
- pointer = (*c)->prox;
- for(; pointer != NULL; pointer = pointer->prox)
- printf("\n %s \n",pointer->dados->str);
- }
- void Pop(cel **c)
- {
- if (!isEmpty(*c)){
- cel *no;
- no = (*c);
- free(no);
- }
- }
- void libera_lista(cel **c)
- {
- cel *no;
- if (!isEmpty(*c)){
- while((*c)->prox != NULL){
- no = (*c);
- (*c) = (*c)->prox;
- free(no);
- }
- }else {
- printf("lista vazia\n");
- }
- }
- int main()
- {
- pessoa p;
- strcpy(p.str,"abc");
- int tam;
- cel *c = cria_cel();
- Push(&c,&p);
- Push(&c,&p);
- //imprime(&c);
- Pop(&c);
- //libera_lista(&c);
- imprime(&c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement