Advertisement
rihardmarius

final 1c - apareo de listas

Nov 24th, 2013
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 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 (p->entry == q->entry)
  23.         {
  24.             insertar_nodo_al_final (c, p->entry);
  25.             p = p->next;
  26.             q = q->next;
  27.         }
  28.         else if (es_menor(p->entry, q->entry))
  29.         {
  30.             insertar_nodo_al_final(c,p->entry);
  31.             p = p->next;
  32.         }
  33.         else
  34.         {
  35.             insertar_nodo_al_final(c,q->entry);
  36.             q = q->next;
  37.         }
  38.     }
  39.     if (p == 0)
  40.         while (q != 0)
  41.         {
  42.             insertar_nodo_al_final(c,q->entry);
  43.             q = q->next;
  44.         }
  45.     else
  46.         while (p != 0)
  47.         {
  48.             insertar_nodo_al_final(c,p->entry);
  49.             p = p->next;
  50.         }
  51. }
  52.  
  53. int main()
  54. {
  55. //    if (es_menor(2,2))
  56. //        cout << "super" << endl;
  57.  
  58.     lista a;
  59.     for (int i = 0; i<10; i++)
  60.         insertar_nodo_al_final(a,i+12);
  61.     mostrar_lista(a);
  62.  
  63.     lista b;
  64.     for (int i = 0; i<10; i++)
  65.         insertar_nodo_al_final(b,i);
  66.     mostrar_lista(b);
  67.  
  68.     lista c;
  69.     apareo_de_listas (a,b,c);
  70.  
  71.     cout << endl;
  72.     mostrar_lista(c);
  73.  
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement