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 ShowList(cel **c)
- {
- cel *pointer;
- pointer = (*c)->prox;
- for(; pointer != NULL; pointer = pointer->prox)
- printf("\n %s \n",pointer->dados->str);
- }
- int sizeList(cel **c)
- {
- int count=0;
- cel *pointer = (*c)->prox;
- for(; pointer != NULL; pointer =pointer->prox)
- count++;
- return count;
- }
- 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()
- {
- int tam_v,_opc,elem;
- pessoa p;
- strcpy(p.str,"abc");
- cel *c = cria_cel();
- //Push(&c,&p);
- //imprime(&c);
- for(;;){
- printf("\n\t(0)---------- SAIR \n");
- printf("\n\t(1)---------- INSERIR ELEMENTO NA LISTA (PUSH) \n");
- printf("\n\t(2)---------- REMOVER ELEMENTO DA LISTA (POP) \n");
- printf("\n\t(3)---------- IMPRIMIR \n");
- printf("\n\t(4)---------- TAMANHO DA LISTA \n");
- printf("\n\t(5)---------- LIBERAR LISTA \n");
- printf("> "); scanf("%d",&_opc);
- switch(_opc){
- case 0:
- exit( 0 );
- default:
- fprintf(stdout,"[-] COMANDO INVALIDO!!! [-]");
- break;
- case 1:
- printf(" Digite (PUSH):\n");
- printf("> "); scanf("%d",&elem);
- break;
- case 2:
- printf("\n POP \n");
- beak;
- case 3:
- ShowList(&c);
- break;
- case 4:
- tam_v = SizeList(&c);
- printf("\n TAMANHO DA LISTA -> [ %d ]\n",tam_v);
- break;
- case 5:
- libera_lsita(&c);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement