Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Bem galera,
estou tendo muita dificuldade em finalizar um exercicio.
tenho um arquivo em txt criando por outro codigo fonte, nele possui em cada linha 50 caracteres.
na programação abaixo devo abrir esse arquivo e ordena-lo em
BubbleSort
Inserction Sort
Selection Sort
Quick Sort"
ja conseguir fazer o programa rodar em BubbleSort,
agradeço pela ajuda
Código do programa:
#include <iostream>
#include <string.h>
#include <fstream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void convertesegundo(int tempo)
{
int hor = tempo/3600;
int seg = tempo%60;
int min = tempo/60;
cout<<"Tempo para gerar aquivo: ";cout<<seg<<endl;
}
void bubbleSort(string *content, int tam)
{
int x;
string temp;
bool sw=true;sw = false;
for(x = 0; x<tam; x++)temp = content[x];
content[x] = content[x+1];
content[x+1] = temp;
sw = true;
}
}
}
}
int main()
{
string line, lines[100001];
int i=0, j=0, op=100, tempo;
time_t tempoinicial;
srand(time(NULL));
char iArqName[50], oArqName[50];
cout << "Informe o nome do arquivo a ordenar> ";
cin.getline(iArqName, 50);
cout << "Informe o nome do arquivo depois de ordenado> ";
cin.getline(oArqName, 50);
ifstream myfile (iArqName);getline (myfile,line);
lines[i] = line;
i++;
}
myfile.close();
i = i-2;
cout << "Arquivo lido com Sucesso!"<<endl;cout << "### SELECIONE O METODO DE ORDENACAO ###"<<endl;
cout << " 1 - Bubble Sort" << endl;
cout << " 2 - Inserction Sort" << endl;
cout << " 3 - Selection Sort" << endl;
cout << " 4 - Quick Sort" <<endl;
cout << "#######################################"<<endl;
cout << "Informe o metodo desejado> ";
cin >> op;
switch(op)
{
case 1:
tempoinicial = time(NULL);
bubbleSort(lines, i);
break;//SELECT
break;cout << "Opcao Invalida!";
}
}
ofstream myFile2(oArqName);myFile2 << lines[j]<<endl;
j++;
}
myFile2.close();
time_t tempofinal(time(NULL));
tempo = tempofinal-tempoinicial;
convertesegundo(tempo);
}
else cout << "Unable to open file";
system("pause");
return 0;
}Carregando comentários...