Guest User

Untitled

a guest
Jun 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef struct s_no{
  4.         int val;
  5.         struct s_no *prox;
  6. }encadeamento;
  7. typedef encadeamento* lista;
  8. void addElemTopo(lista *p_L, int x);
  9. int main(int argc, char *argv[])
  10. {
  11.   int numero, x = 0, y;
  12.   char opcao;
  13.   lista primeiro = NULL, tmp, temp;
  14.   do{
  15.      printf("Informe o valor para ser colocado na lista:\n");
  16.      scanf("%d", &numero);
  17.      if(numero != -1)
  18.          addElemTopo(&primeiro, numero);
  19.      system("CLS");
  20.      x++;
  21.   }while(numero != -1);
  22.   temp = primeiro;
  23.   printf("LISTA -> ");
  24.   while(temp != NULL){
  25.      printf("%d ", temp->val);
  26.      temp = temp->prox;          
  27.   }
  28.   getch();
  29.   return 0;
  30. }
  31. void addElemTopo(lista *p_L, int x) {
  32.   encadeamento *tmp;
  33.   tmp=(encadeamento*)malloc(sizeof(encadeamento));/*1-criar uma nova cel */
  34.   tmp->prox=*p_L;     /*2- apontando p/ lista*/
  35.   (*p_L)=tmp;         /*3-elemento é o novo primeiro*/
  36.   (*p_L)->val=x;      /*armazenar o valor do elemento*/
  37. }
Add Comment
Please, Sign In to add comment