Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- void LeerElemDetectandoFin(fstream &arch, string &comp, bool &finArch);
- void PasarElemDetectandoFin(fstream &archOrigen,fstream &archDestino, string &comp, bool &finArchOrigen);
- void Mezcla(fstream &aux1,fstream &aux2,fstream &arch);
- void Division(fstream &arch,fstream &aux1,fstream &aux2,bool &esVacio2);
- int main(int argc, char **argv)
- {
- fstream arch,aux1,aux2;
- bool esVacio2 = false;
- while(!esVacio2)
- {
- arch.open(argv[1],ios::in);
- aux1.open(argv[2],ios::out);
- aux2.open(argv[3],ios::out);
- Division(arch,aux1,aux2,esVacio2);
- arch.close();
- aux1.close();
- aux2.close();
- aux1.open(argv[2],ios::in);
- aux2.open(argv[3],ios::in);
- arch.open(argv[1],ios::out);
- Mezcla(arch,aux1,aux2);
- aux1.close();
- aux2.close();
- arch.close();
- }
- return 0;
- }
- void LeerElemDetectandoFin(fstream &arch, string &comp, bool &finArch)
- {
- finArch = arch.eof();
- if(!finArch)
- getline(arch,comp);
- }
- void PasarElemDetectandoFin(fstream &archOrigen,fstream &archDestino, string &comp, bool &finArchOrigen)
- {
- archDestino<<comp;
- LeerElemDetectandoFin(archOrigen,comp,finArchOrigen);
- }
- void Division(fstream &arch,fstream &aux1,fstream &aux2,bool &esVacio2)
- {
- string valorActual,valorAnterior;
- bool cambio = true;
- esVacio2 = true;
- if(!arch.eof()){
- getline(arch,valorActual);
- aux1<<valorActual;
- valorAnterior = valorActual;
- }
- while(!arch.eof()){
- getline(arch,valorActual);
- if(valorAnterior > valorActual)
- cambio = !cambio;
- if(cambio)
- aux1<<valorActual;
- else{
- aux2<<valorActual;
- esVacio2 = false;
- }
- valorAnterior = valorActual;
- }
- }
- void Mezcla(fstream &aux1,fstream &aux2,fstream &arch)
- {
- string c1,c2;
- bool finArch1,finArch2;
- LeerElemDetectandoFin(aux1,c1,finArch1);
- LeerElemDetectandoFin(aux2,c2,finArch2);
- while(!finArch1 && !finArch2)
- if(c1 < c2)
- PasarElemDetectandoFin(aux1,arch,c1,finArch1);
- else
- PasarElemDetectandoFin(aux2,arch,c2,finArch2);
- while(!finArch1)
- PasarElemDetectandoFin(aux1,arch,c1,finArch1);
- while(!finArch2)
- PasarElemDetectandoFin(aux2,arch,c2,finArch2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement