Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct elemento Elemento;
  5. struct elemento{
  6. int info;
  7. Elemento*prox;
  8. };
  9.  
  10. Elemento* lst_cria(void){
  11. return NULL;
  12. }
  13.  
  14. Elemento* lst_insere(Elemento*lst,int val){
  15. Elemento*novo = (Elemento*)malloc(sizeof(Elemento));
  16. novo->info= val;
  17. novo->prox= lst;
  18. return novo;
  19. }
  20.  
  21. Elemento* copia(Elemento*lst,Elemento*q){
  22. Elemento*p;
  23. q=(Elemento*) malloc(sizeof(Elemento));
  24. for(p=lst;p!=NULL;p=p->prox){
  25. for(;q!=NULL;q=q->prox){
  26. q->prox=(Elemento*) malloc(sizeof(Elemento));
  27. q->info= p->info;
  28. q->prox= p->prox;
  29. }
  30. }
  31. }
  32.  
  33. void imprime_copia(Elemento*q){
  34. Elemento*b;
  35. for(b=q;b!=NULL;b=b->prox){
  36. printf("copia= %d\n",b->info);
  37. }
  38. }
  39.  
  40. void imprime(Elemento*lst){
  41. Elemento*a;
  42. for(a=lst;a!=NULL;a=a->prox){
  43. printf("info= %d\n",a->info);
  44. }
  45. }
  46.  
  47. int main()
  48. {
  49. Elemento*lst;
  50. Elemento*q;
  51.  
  52. lst= lst_cria();
  53. q= lst_cria();
  54.  
  55. lst= lst_insere(lst,1);
  56. lst= lst_insere(lst,3);
  57. lst= lst_insere(lst,5);
  58.  
  59. imprime(lst);
  60. copia(lst,q);
  61. imprime_copia(q);
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement