Guest User

Untitled

a guest
Feb 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. struct ptr{
  4. int dado;
  5. struct ptr *ant,*prox;
  6. };
  7. struct ptr *inicio, *aux1, *aux2;
  8. struct desc{
  9. int quant;
  10. struct ptr *prim,*ult;
  11. };
  12. struct desc *lista;
  13. void lista_vazia_desc(){
  14. lista=(struct desc *)malloc(sizeof(struct desc));
  15. lista->quant=0;
  16. lista->prim=(struct ptr *)NULL;
  17. lista->ult=lista->prim;
  18. }
  19. main(){
  20. int dado;
  21. void lista_vazia_desc();
  22. inicio=(struct ptr*)malloc(sizeof(struct ptr));
  23. inicio->prox=(struct ptr *)NULL;
  24. inicio->ant=(struct ptr *)NULL;
  25. printf("Entre com o valor:\n");
  26. scanf("%d",&dado);
  27. while(dado>=0){
  28. if(inicio->prox==(struct list*)NULL){
  29. lista->prim=inicio;
  30. lista->ult=inicio;
  31. inicio->dado=dado;
  32. inicio->prox=inicio;
  33. inicio->ant=inicio;
  34. lista->quant++;
  35. aux2=inicio;
  36. printf("Entre com o valor:\n");
  37. scanf("%d",&dado);
  38. }
  39. else{
  40. aux1=(struct ptr*)malloc(sizeof(struct ptr));
  41. aux1->dado=dado;
  42. aux2->prox=aux1;
  43. aux2->ant=aux1;
  44. aux1->ant=aux2;
  45. aux2=aux1;
  46. lista->ult=aux2;
  47. lista->quant++;
  48. aux2->prox=inicio;
  49. printf("Entre com o valor:\n");
  50. scanf("%d",&dado);
  51. }
  52. }
  53. getch();
  54. }
Add Comment
Please, Sign In to add comment