It is as follows: I need to find in a .txt file a certain sequence of 10 characters for example AAAAACCCCC only that this sequence should be found by different sorting methods (direct insertion, binary insertion, selection, bubblesort, heapsort, quicksort and quick binary search ) And should display how many moves and comparisons were made in each method until you find the sequence.
And here comes the problem, as I do this, I coded a part, but at the time of opening the file in the methods I could not.
Someone, please, could you give me a hand.
> I used Google translate to English
the result is quite amazing.
> //#include<iostream.h>
¿is this a "c++" course?
1 2 3 4 5 6 7
//fill the vector with the contens fo the file
std::ifstream input("seq_1.txt");
std::vector<std::string> v;
v.reserve(42); //choose a good estimate
std::string sequence;
while( input >> sequence )
v.push_back(sequence);
your sorting algorithms would work as std::string understand comparison operators (<,>,==)
only need to change the type of the parameters, for example
1 2 3
//void BubbleSort(int vetor[], int tamanho)
void BubbleSort(std::vector<std::string> vetor){
int tamanho = vetor.size();
If you want it in c
1 2 3 4 5 6 7 8
//fill the vector with the contens fo the file
FILE *input = fopen("seq1.txt", "r");
//each sequence has size 10+1 (for the '\0' terminator)
//oversize the array
char v[11][1000000];
int tamanho = 0;
while(fscanf(input, "%s", v[tamanho]) != EOF) //not sure about this, check it out
++tamanho;
then to compare each element you'll need to use strcmp() instead of <,>,==
1 2 3 4 5
/*if(num[j] > num[min]) {
min = j;
}*/
if( strcmp(v[j], v[min]) > 0 )
min = j;