2つの別々のアレイから読み込み、LSTestのアレイの値がLSStandardの配列に含まれているかどうかを確認することが主な目的です。アレイからアレイへのリニアサーチ
LSTest [j] == LSTest [i]の場合、結果は と表示されます。
LSTest [j]が関数内でLSStandard [i]を検出する回数が複数あることがあります。例えば、LSTTest [j]は9であり、LSStandard [1]とLSStandard [10] ]
LSTestは50個の整数です。 LSStandardは100の整数です。あなたが適切linearSearch
関数を宣言しているが、がそれを定義していないため、コンパイルされません通常の状況で
// ConsoleApplication78.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <fstream>
using namespace std;
int linearSearch(ifstream, int[], int, int[], int);
// Program Main
int main()
{
ifstream FIN_LSS ("LSStandard.txt");
ifstream FIN_LST ("LSTest.txt");
int const LSSlength = 100;
int const LSTlength = 50;
int getSearchNumber;
// int exme;
int LSSArray[LSSlength];
int LSTArray[LSTlength];
if (!FIN_LSS.fail())
{
cout << "'LSStandard.txt' opened successfully." << endl << endl;
if (!FIN_LST.fail())
{
cout << "'LSTest.txt' opened successfully." << endl << endl;
while (FIN_LSS >> LSSArray[LSSlength])
{
{
int result = linearSearch(FIN_LST, LSTArray[], LSTlength,
LSSArray[], LSSlength);
if (result >= 0)
{
cout << "The number " << LSSArray[result] << "was found at: " << result << " index " << endl;
}
else
{
// cout << "Nothing was found" << endl;
}
}
}
}
}
return 0;
}
int linearSearch(ifstream FIN_LST, int LSTArray[], int LSTlength,
int LSSArray[], int LSSlength)
{
int i; // counter variable
int j; // counter variable
for (j = 0; j < LSTlength; j++)
{
while (FIN_LST >> LSTArray[LSTlength])
{
for (i = 0; i < LSSlength; i++)
{
if (LSTArray[j] == LSSArray[i]) {
return i;
}
}
}
}
return -1;
}
あなたの質問は? –
FYIでは、一般的なコーディングガイドラインでは、マクロと定数(少なくともマクロ)のすべてのCAPS名を予約しています。変数名と関数名は、先頭のアンダースコア(コンパイラによって予約されている可能性があります)を除いて、他の組み合わせでなければなりません。 –