Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #include<conio.h>
  2. #include<stdlib.h>
  3. #include<stdio.h>
  4.  
  5. struct node
  6. {
  7. int info;
  8. struct node *ant;
  9. struct node *prox;
  10. };
  11. typedef struct node *listadup;
  12.  
  13. listadup getNode()
  14. {
  15. listadup novo;
  16. novo=(listadup)malloc(sizeof(struct node));
  17. return novo;
  18. }
  19. void insereInicio(int x, listadup *inicio, listadup *fim)
  20. {
  21. listadup novo;
  22. novo = (listadup)malloc(sizeof(struct node));
  23. if (novo == NULL)
  24. {
  25. puts("noh nao alocado");
  26. getch ();
  27. }
  28. else
  29. {
  30. novo->info = x;
  31. if(*inicio == NULL)
  32. {
  33. novo->prox=NULL;
  34. novo->ant=NULL;
  35. *inicio=novo;
  36. *fim=novo;
  37. }
  38. else
  39. {
  40. novo->prox = *inicio;
  41. novo->ant = NULL;
  42. *inicio = novo;
  43. *fim = novo;
  44. }
  45. }
  46. }
  47.  
  48. void insereFim(int x, listadup *inicio, listadup *fim)
  49. {
  50. listadup novo;
  51. if(*inicio == NULL)
  52. {
  53. insereInicio(x,&*inicio,&*fim);
  54. }
  55. else
  56. {
  57. novo = (listadup)malloc(sizeof(struct node));
  58.  
  59. if (novo == NULL)
  60. {
  61. puts("noh nao alocado");
  62. getch ();
  63. }
  64. else
  65. {
  66. novo->info = x;
  67. novo->ant = *fim;
  68. novo->prox =NULL;
  69. (*fim)->prox = novo;
  70. *fim = novo;
  71. }
  72. }
  73. }
  74.  
  75.  
  76. void exibeLista(listadup inicio)
  77. {
  78. if(inicio == NULL)
  79. {
  80. puts("lista vazia");
  81. getch();
  82. }
  83. else
  84. {
  85. while(inicio!=NULL)
  86. {
  87. printf("\n%d",inicio->info);
  88. inicio=inicio->prox;
  89. }
  90. getch();
  91. }
  92. }
  93.  
  94. void copiadaLista(listadup *inicio, listadup *fim, listadup *inicio2 ,listadup *fim2)
  95. {
  96. listadup aux,aux2;
  97. int x;
  98. if(*inicio == NULL)
  99. {
  100. puts("lista vazia:");
  101. getch();
  102. }
  103. else
  104. {
  105. aux=*inicio;
  106. while(aux!=NULL)
  107. {
  108. x=aux->info;
  109. insereFim(x,inicio2,fim2);
  110. aux=aux->prox;
  111. }
  112. }
  113. }
  114.  
  115.  
  116. int main()
  117. {
  118. listadup inicio,fim,inicio2,fim2;
  119. inicio = fim =inicio2 = fim2 = NULL;
  120. insereInicio(10,&inicio,&fim);
  121. insereFim(20,&inicio,&fim);
  122. insereFim(30,&inicio,&fim);
  123. insereFim(40,&inicio,&fim);
  124. exibeLista(inicio);
  125. exibeLista(inicio2);
  126. copiadaLista(&inicio,&fim,&inicio2,&fim2);
  127. return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement