是否可以为在其参数列表中具有模板类的函数制作模板?
我想为 statSelection() 和 statInsertion() 制作一个模板,这样我就可以测试不同的排序算法,而不必为我正在测试的每种排序算法创建单独的 stat 函数。(我的排序算法是模板类)
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include "FileGen.h"
#include "FileRead.h"
#include "SelectionSort.h"
#include "SelectionSort.cpp"
#include "InsertionSort.h"
#include "InsertionSort.cpp"
using namespace std;
void statSelection(int[], int[], Selection<int>, Selection<int>);
void statInsertion(int[], int[], Insertion<int>, Insertion<int>);
int main ()
{
FileGen fileGen;
FileRead fileRead;
Selection<int> selectHundred;
Selection<int> selectThousand;
Insertion<int> insertionHundred;
Insertion<int> insertionThousand;
int valuesHundred[100];
int valuesThousand[1000];
fileGen.generateFiles();
fileRead.readFiles(valuesHundred, valuesThousand);
statSelection(valuesHundred, valuesThousand, selectHundred, selectThousand);
fileGen.generateFiles();
fileRead.readFiles(valuesHundred, valuesThousand);
statInsertion(valuesHundred, valuesThousand, insertionHundred, insertionThousand);
system("pause");
return 0;
}
void statSelection(int vHundred[], int vThousand[], Selection<int> sHundred, Selection<int> sThousand)
{
cout << "One Hundred Items" << endl;
sHundred.SelectionSort(vHundred, 100);
sHundred.selectionSortPreformance();
cout << "One Thousand Items" << endl;
sThousand.SelectionSort(vThousand, 1000);
sThousand.selectionSortPreformance();
}
void statInsertion(int vHundred[], int vThousand[], Insertion<int> iHundred, Insertion<int> iThousand)
{
cout << "One Hundred Items" << endl;
iHundred.InsertionSort(vHundred, 100);
iHundred.insertionSortPreformance();
cout << "One Thousand Items" << endl;
iThousand.InsertionSort(vThousand, 1000);
iThousand.insertionSortPreformance();
}