Ir ao conteúdo
  • Cadastre-se

Tatiane

Membro Júnior
  • Posts

    3
  • Cadastrado em

  • Última visita

Tudo que Tatiane postou

  1. Nesse caso aqui não seria "start" ao invés de "head"?
  2. Isso, estou com dificuldade para desenvolver essa parte para colocar os números em ordem crescente. Obrigada pela dica do return..
  3. Boa tarde preciso implementar em linguagem C a função de ordenação crescente da lista e não estou conseguindo. Alguém poderia me auxiliar #include <stdio.h> #include <stdlib.h> #include <locale.h> typedef struct BLOCO{ int dado; struct BLOCO *prox; }BLOCO; typedef struct LISTA{ BLOCO *start; BLOCO *end; }LISTA; void startLISTA(LISTA *l){ l->start = NULL; l->end = NULL; } void insereLista_cabeca(int dado, LISTA *l){ BLOCO *ptr_aux = (BLOCO*)malloc(sizeof(BLOCO)); if (ptr_aux == NULL){ printf("Memory Allocation Error"); exit(-1); } else{ ptr_aux->dado = dado; ptr_aux->prox = NULL; if(l->start == NULL){ l->start = ptr_aux; l->end = ptr_aux; } else{ ptr_aux->prox = l->start; l->start = ptr_aux; } } } void insereLista_cauda(int dado, LISTA *l){ BLOCO *ptr_aux = (BLOCO*)malloc(sizeof(BLOCO)); if (ptr_aux == NULL){ printf("Memory Allocation Error"); exit(-1); } else{ ptr_aux->dado = dado; ptr_aux->prox = NULL; if(l->start == NULL){ l->start = ptr_aux; l->end = ptr_aux; } else{ l->end->prox = ptr_aux; //ptr_aux->prox = NULL; l->end = ptr_aux; } } } int removeLista_cabeca(LISTA *l){ BLOCO *ptr_aux = l->start; int dado; if(ptr_aux != NULL){ l->start = ptr_aux->prox; ptr_aux->prox = NULL; dado = ptr_aux->dado; free(ptr_aux); if(l->start == NULL){ l->end = NULL; } return dado; } else{ printf("LIST is Empty \n"); } return dado; } int removeLista_cauda(LISTA *l){ BLOCO *ptr_aux_ant; BLOCO *ptr_aux = l->start; int dado; if(ptr_aux != NULL){ while (ptr_aux->prox != NULL){ ptr_aux_ant = ptr_aux; ptr_aux = ptr_aux->prox; } l->end = ptr_aux_ant; ptr_aux_ant->prox = NULL; //l->start = ptr_aux->prox; //ptr_aux->prox = NULL; dado = ptr_aux->dado; free(ptr_aux); if(l->start == NULL){ l->end = NULL; } return dado; } else{ printf("LIST is Empty \n"); } return dado; } int removeLista_elemento(int dado, LISTA *l){ BLOCO *ptr_aux_ant = l->start; BLOCO *ptr_aux = l->start; if(ptr_aux != NULL){ while (ptr_aux->prox != NULL){ if (ptr_aux->dado == dado){ if (ptr_aux_ant == ptr_aux){ removeLista_cabeca(l); } else{ ptr_aux_ant->prox = ptr_aux->prox; ptr_aux->prox = NULL; return ptr_aux->dado; free(ptr_aux); } } ptr_aux_ant = ptr_aux; ptr_aux = ptr_aux->prox; } if (ptr_aux->prox == NULL){ removeLista_cauda(l); } //l->end = ptr; //ptr->prox = NULL; //l->start = ptr_aux->prox; //ptr_aux->prox = NULL; //dado = ptr_aux->dado; //free(ptr_aux); if(l->start == NULL){ l->end = NULL; } return dado; } else{ printf("LIST is Empty \n"); } return dado; } void printLISTA(LISTA *l){ BLOCO *ptr_print = l->start; if(ptr_print != NULL){ while (ptr_print != NULL){ printf("%d ", ptr_print->dado); ptr_print = ptr_print->prox; } } else{ printf("LISTA is Empty"); return; } printf("\n"); } int main(){ LISTA *li = (LISTA*) malloc(sizeof(LISTA)); if (li == NULL){ printf("Memory Allocation Error"); exit(-1); } else{ startLISTA(li); insereLista_cabeca(1, li); printLISTA(li); insereLista_cabeca(12, li); printLISTA(li); insereLista_cabeca(15, li); printLISTA(li); insereLista_cauda(20, li); printLISTA(li); insereLista_cauda(25, li); printLISTA(li); removeLista_cabeca(li); printLISTA(li); removeLista_cabeca(li); printLISTA(li); //removeLista_cauda(li); //printLISTA(li); //removeLista_cabeca(li); removeLista_elemento(20, li); printLISTA(li); removeLista_elemento(25, li); printLISTA(li); } }

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!