我怎樣才能獲得dValues[]
在該行double dValues[] = {what should i input here?}
?因爲我使用的數組。目標是獲得模式。如何從一個矢量的值複製到一個數組?
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
double GetMode(double daArray[], int iSize) {
// Allocate an int array of the same size to hold the
// repetition count
int* ipRepetition = new int[iSize];
for (int i = 0; i < iSize; ++i) {
ipRepetition[i] = 0;
int j = 0;
bool bFound = false;
while ((j < i) && (daArray[i] != daArray[j])) {
if (daArray[i] != daArray[j]) {
++j;
}
}
++(ipRepetition[j]);
}
int iMaxRepeat = 0;
for (int i = 1; i < iSize; ++i) {
if (ipRepetition[i] > ipRepetition[iMaxRepeat]) {
iMaxRepeat = i;
}
}
delete [] ipRepetition;
return daArray[iMaxRepeat];
}
int main()
{
int count, minusElements;
float newcount, twocount;
cout << "Enter Elements:";
std::cin >> count;
std::vector<float> number(count);
cout << "Enter " << count << " number:\n";
for(int i=0; i< count ;i++)
{
std::cin >> number[i];
}
double dValues[] = {};
int iArraySize = count;
std::cout << "Mode = "
<< GetMode(dValues, iArraySize) << std::endl;
你的問題,請詳細說明。 – erisco
上一行:雙dValues [] = {};在括號中,我應該輸入什麼來獲取我輸入的變量? – John