Advertisement
rihardmarius

final 7.12.13 - v2

Dec 13th, 2013
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. #include "libreria.h"
  5.  
  6. void fusionar (string& n, lista& l, lista& p)
  7. {
  8.     ifstream input (n);
  9.     if (not input.is_open())
  10.     {
  11.         cout << "Archivo no encontrado" << endl;
  12.         return;
  13.     }
  14.     registro R; int grupo_ant;
  15.     nodo2* lista = l.root;
  16.     nodo1* sublista;
  17.  
  18.     bool b = leer_especial(input,R);
  19.     while (lista != 0 and b)
  20.     {
  21.         if (lista->grupo < R.grupo)
  22.         {
  23.             insertar_grupo(p, lista->grupo);
  24.             sublista = lista->sublista;
  25.             while(sublista != nullptr)
  26.             {
  27.                 insertar_valor_en_grupo(p, lista->grupo, sublista->valor);
  28.                 sublista = sublista->next;
  29.             }
  30.             lista = lista->next;
  31.         }
  32.         else if (lista->grupo > R.grupo)
  33.         {
  34.             insertar_grupo(p, R.grupo);
  35.             grupo_ant = R.grupo;
  36.             while (b and R.grupo == grupo_ant)
  37.             {
  38.                 insertar_valor_en_grupo(p, R.grupo, R.valor);
  39.                 b = leer_especial(input, R);
  40.             }
  41.         }
  42.         else if (lista->grupo == R.grupo)
  43.         {
  44.             insertar_grupo(p, lista->grupo);
  45.             sublista = lista->sublista;
  46.             while(sublista != nullptr)
  47.             {
  48.                 insertar_valor_en_grupo(p, lista->grupo, sublista->valor);
  49.                 sublista = sublista->next;
  50.             }
  51.             lista = lista->next;
  52.             grupo_ant = R.grupo;
  53.             while (b and R.grupo == grupo_ant)
  54.             {
  55.                 insertar_valor_en_grupo (p, R.grupo, R.valor);
  56.                 b = leer_especial(input, R);
  57.             }
  58.         }
  59.     }
  60.     if (lista == nullptr)
  61.     {
  62.         while (b)
  63.         {
  64.             insertar_grupo (p, R.grupo);
  65.             grupo_ant = R.grupo;
  66.             while (b and R.grupo == grupo_ant)
  67.             {
  68.                 insertar_valor_en_grupo(p, R.grupo, R.valor);
  69.                 b = leer_especial (input, R);
  70.             }
  71.         }
  72.     }
  73.     else
  74.     {
  75.         while (lista != nullptr)
  76.         {
  77.             insertar_grupo (p, lista->grupo);
  78.             grupo_ant = lista->grupo;
  79.             sublista = lista->sublista;
  80.             while (sublista != nullptr)
  81.             {
  82.                 insertar_valor_en_grupo(p, lista->grupo, sublista->valor);
  83.                 sublista = sublista->next;
  84.             }
  85.             lista = lista->next;
  86.         }
  87.     }
  88. }
  89.  
  90.  
  91. int main()
  92. {
  93.     lista l; lista p;
  94.  
  95.     insertar_grupo(l, 2);
  96.     insertar_grupo(l, 5);
  97.     insertar_grupo(l, 17);
  98.     insertar_grupo(l, 23);
  99.  
  100.     insertar_valor_en_grupo(l, 2, 'b');
  101.     insertar_valor_en_grupo(l, 2, 'e');
  102.     insertar_valor_en_grupo(l, 2, 'z');
  103.     insertar_valor_en_grupo(l, 17, 'r');
  104.     insertar_valor_en_grupo(l, 17, 'y');
  105.     insertar_valor_en_grupo(l, 23, 'f');
  106.     insertar_valor_en_grupo(l, 23, 'j');
  107.     insertar_valor_en_grupo(l, 23, 'p');
  108.     insertar_valor_en_grupo(l, 23, 't');
  109.  
  110.     //mostrar_lista(l);
  111.  
  112.  
  113.     //cout << "Inserte el nombre del archivo: " << endl << endl;
  114.     string nombre = "archivo.txt";
  115.  
  116.     fusionar(nombre, l, p);
  117.  
  118.     mostrar_lista(p);
  119.  
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement