Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- #include "libreria.h"
- void fusionar (string& n, lista& l, lista& p)
- {
- ifstream input (n);
- if (not input.is_open())
- {
- cout << "Archivo no encontrado" << endl;
- return;
- }
- registro R; int grupo_ant;
- nodo2* lista = l.root;
- nodo1* sublista;
- bool b = leer_especial(input,R);
- while (lista != 0 and b)
- {
- if (lista->grupo < R.grupo)
- {
- insertar_grupo(p, lista->grupo);
- sublista = lista->sublista;
- while(sublista != nullptr)
- {
- insertar_valor_en_grupo(p, lista->grupo, sublista->valor);
- sublista = sublista->next;
- }
- lista = lista->next;
- }
- else if (lista->grupo > R.grupo)
- {
- insertar_grupo(p, R.grupo);
- grupo_ant = R.grupo;
- while (b and R.grupo == grupo_ant)
- {
- insertar_valor_en_grupo(p, R.grupo, R.valor);
- b = leer_especial(input, R);
- }
- }
- else if (lista->grupo == R.grupo)
- {
- insertar_grupo(p, lista->grupo);
- sublista = lista->sublista;
- while(sublista != nullptr)
- {
- insertar_valor_en_grupo(p, lista->grupo, sublista->valor);
- sublista = sublista->next;
- }
- lista = lista->next;
- grupo_ant = R.grupo;
- while (b and R.grupo == grupo_ant)
- {
- insertar_valor_en_grupo (p, R.grupo, R.valor);
- b = leer_especial(input, R);
- }
- }
- }
- if (lista == nullptr)
- {
- while (b)
- {
- insertar_grupo (p, R.grupo);
- grupo_ant = R.grupo;
- while (b and R.grupo == grupo_ant)
- {
- insertar_valor_en_grupo(p, R.grupo, R.valor);
- b = leer_especial (input, R);
- }
- }
- }
- else
- {
- while (lista != nullptr)
- {
- insertar_grupo (p, lista->grupo);
- grupo_ant = lista->grupo;
- sublista = lista->sublista;
- while (sublista != nullptr)
- {
- insertar_valor_en_grupo(p, lista->grupo, sublista->valor);
- sublista = sublista->next;
- }
- lista = lista->next;
- }
- }
- }
- int main()
- {
- lista l; lista p;
- insertar_grupo(l, 2);
- insertar_grupo(l, 5);
- insertar_grupo(l, 17);
- insertar_grupo(l, 23);
- insertar_valor_en_grupo(l, 2, 'b');
- insertar_valor_en_grupo(l, 2, 'e');
- insertar_valor_en_grupo(l, 2, 'z');
- insertar_valor_en_grupo(l, 17, 'r');
- insertar_valor_en_grupo(l, 17, 'y');
- insertar_valor_en_grupo(l, 23, 'f');
- insertar_valor_en_grupo(l, 23, 'j');
- insertar_valor_en_grupo(l, 23, 'p');
- insertar_valor_en_grupo(l, 23, 't');
- //mostrar_lista(l);
- //cout << "Inserte el nombre del archivo: " << endl << endl;
- string nombre = "archivo.txt";
- fusionar(nombre, l, p);
- mostrar_lista(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement