Advertisement
rihardmarius

apareo de listas

Dec 8th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include "listas_libreria.txt"
  4.  
  5. // apareo de listas
  6.  
  7. bool es_menor (int a, int b)
  8. {
  9.     if (a < b)
  10.         return true;
  11.     else
  12.         return false;
  13. }
  14.  
  15. void apareo_de_listas (lista& a, lista& b, lista& c)
  16. {
  17.     node* p = a.root;
  18.     node* q = b.root;
  19.  
  20.     while (p != 0 and q != 0)
  21.     {
  22.         if (es_menor(p->entry, q->entry))
  23.         {
  24.             insertar_nodo_al_final(c,p->entry);
  25.             p = p->next;
  26.         }
  27.         else
  28.         {
  29.             insertar_nodo_al_final(c,q->entry);
  30.             q = q->next;
  31.         }
  32.     }
  33.     if (p == 0)
  34.         p = q;
  35.  
  36.     while (p != 0)
  37.     {
  38.         insertar_nodo_al_final(c,p->entry);
  39.         p = p->next;
  40.     }
  41. }
  42.  
  43. int main()
  44. {
  45.     lista a;
  46.     for (int i = 0; i<10; i+=2)
  47.         insertar_nodo_al_final(a,i);
  48.     mostrar_lista(a);
  49.  
  50.     lista b;
  51.     for (int i = 1; i<10; i+=2)
  52.         insertar_nodo_al_final(b,i);
  53.     mostrar_lista(b);
  54.  
  55.     lista c;
  56.     apareo_de_listas (a,b,c);
  57.  
  58.     cout << endl;
  59.     mostrar_lista(c);
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement