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],x,v[MAX];
- char str[MAX];
- };
- typedef struct Pessoa pessoa;
- typedef struct Celula {
- pessoa *dados;
- struct Celula *ant;
- struct Celula *prox;
- }cel;
- int size =0x0;
- 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;
- }
- size++;
- return true;
- }
- void ShowList(cel **c)
- {
- size_t count=0;
- cel *pointer;
- pointer = (*c)->prox;
- if(isEmpty(*c))
- printf("----LISTA VAZIA----");
- if (!isEmpty(*c))
- for(; count <= size; count++)
- printf("%d \n",pointer->dados->vetor[count]);
- }
- int sizeList(cel **c)
- {
- size_t count = 0;
- if (!isEmpty(*c)){
- cel *pointer = (*c)->prox;
- for(; pointer != NULL; pointer =pointer->prox)
- count++;
- }if (isEmpty(*c))
- printf("----LISTA VAZIA----");
- return count;
- }
- void libera_lista(cel **c)
- {
- cel *no;
- if (!isEmpty(*c)){
- while((*c)->prox != NULL){
- no = (*c);
- (*c) = (*c)->prox;
- free(no);
- size--;
- }
- }if(isEmpty(*c))
- printf("\n ----LISTA VAZIA----\n");
- }
- bool SearchList(cel **c,pessoa *_elem)
- {
- cel *pointer=(*c)->prox;
- cel *aux;
- int i=0;
- if (!isEmpty(*c))
- for(; i <=size; i++){
- if (pointer->dados->vetor[i] == *_elem){
- printf("\nENCONTRADO \n");
- }else{
- printf("\nnao encontrado\n");
- }
- }
- if(isEmpty(*c))
- fprintf(stdout,"----LISTA VAZIA----");
- return false;
- }
- int main()
- {
- int _opc,elem,pos,tam_v;
- pessoa p;
- cel *c = cria_cel();
- for(;;){
- printf("\n\t(0)---------- SAIR ");
- printf("\n\t(1)---------- INSERIR ELEMENTO NO INICIO DA LISTA (PUSH) ");
- printf("\n\t(2)---------- REMOVER ELEMENTO DA LISTA (POP) ");
- printf("\n\t(3)---------- IMPRIMIR ");
- printf("\n\t(4)---------- TAMANHO DA LISTA ");
- printf("\n\t(5)---------- BUSCAR LISTA (SEARCH) ");
- printf("\n\t(6)---------- LIBERAR LISTA \n");
- printf("> "); scanf("%d",&_opc);
- switch(_opc){
- case 0:
- exit( 0 );
- // break;
- default:
- fprintf(stdout,"[-] COMANDO INVALIDO!!! [-]");
- break;
- case 1:
- printf(" Digite (PUSH) e a posicao do vetor :\n");
- printf("> "); scanf("%d %d",&elem,&pos);
- p.vetor[pos] =elem;
- Push(&c,&p);
- break;
- case 2:
- printf("\n POP \n");
- break;
- case 3:
- ShowList(&c);
- break;
- case 4:
- tam_v = sizeList(&c);
- printf("\n TAMANHO DA LISTA -> [ %d ]\n",tam_v);
- break;
- case 5:
- printf("Digite o item de busca: ");
- scanf("%d",&elem);
- p.x = elem;
- SearchList(&c,&p);
- break;
- case 6:
- libera_lista(&c);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement