Witam serdecznie.
Borykam się w sumie z jednym, końcowym już problemem podczas pisania programu. Przejrzalem nie tylko polskie fora ale i anglojęzyczne, włącznie z ebookami itp., ale nadal pomimo wykorzystywania podręcznikowych przykładów nie wychodzi mi to.
Poniżej załącze kod:
void testing( void (*sortType)( vector<int> ) )
{
string fileName;
ostringstream id;
for( int i=0; i<elements; i++ )
{
double tstart, tstop, ttime;
vector<int> data;
id << gTable[i];
fileName = "random[" + id.str() + "].txt";
readFile( fileName, data );
tstart = (double)clock();
( *sortType )( data );
tstop = (double)clock();
ttime = tstop - tstart;
cout << "Random[" + id.str() + "]: " << ttime << endl;
id.str("");
}
for( int i=0; i<elements; i++ )
{
double tstart, tstop, ttime;
vector<int> data;
id << gTable[i];
fileName = "sorted[" + id.str() + "].txt";
readFile( fileName, data );
tstart = (double)clock();
(*sortType)( data );
tstop = (double)clock();
ttime = tstop - tstart;
cout << "Sorted[" + id.str() + "]: " << ttime << endl;
id.str("");
}
for( int i=0; i<elements; i++ )
{
double tstart, tstop, ttime;
vector<int> data;
id << gTable[i];
fileName = "inv_sorted[" + id.str() + "].txt";
readFile( fileName, data );
tstart = (double)clock();
(*sortType)( data );
tstop = (double)clock();
ttime = tstop - tstart;
cout << "Inv_Sorted[" + id.str() + "]: " << ttime << endl;
id.str("");
}
}
void bubble()
{
system( "cls" );
cout << "Testing in progress..." << endl << endl;
vector<int> data;
testing( bubbleTest( data ) );
cout << "Press any key to quit...";
_getch();
}
//END EXPLORE
//BEGIN SORT TYPE
void bubbleTest( vector<int> &tab )
{
int i, temp;
bool finished = false;
while (!finished)
{
finished = true;
for( i = 0; i < tab.size()-1; i++ )
{
if( tab[i] > tab[i+1] )
{
temp = tab[i];
tab[i] = tab[i+1];
tab[i+1] = temp;
finished=false;
}
}
}
}
Chodzi mi o to by w funkcji bubble() podac funkcję sortowania, która ma być podstawiona w każdym stosownym miejscu w funkcji testing.
Nie jestem raczej dobry z programowania, dopiero się uczę, wiem, że jeszcze sporo przede mną, ale będę bardzo wdzięczny za pomoc w rozwikłaniu tego problemu.