我有一個線性搜索算法設置爲通過類對象的數組來搜索它的工作,但輸出不匹配,當我搜索數組中的particluar名稱的第一個和第三個值INT數組中找到但第二個值沒有找到..線性搜索類對象的數組
以下是我的代碼感謝您的幫助。
int linsearch(string val)
{
for (int j=0; j <= 3; j++)
{
if (player[j].getLastName()==val)
return j ;
}
return 1 ;
}
void showinfo()
{
string search;
int found ;
cout << "Please Enter The Player's Last Name : " ;
cin >> search ;
found=linsearch(search);
if (found==1)
{
cout << "\n There is no player called " << search ;
}
else
{
cout << "\n First Name : " << player[found].getFirstName() << "\n" << "Last Name : " << player[found].getLastName() <<
"\n" << "Age : " << player[found].getAge() << "\n" << "Current Team : " << player[found].getCurrentTeam() <<
"\n" << "Position : " << player[found].getPosition() << "\n" << "Status : " << player[found].getStatus() << "\n\n";
}
cin.get() ;
menu() ;
}
謝謝你,看到我的mistak e .. – tarantino
我可以向OP建議他使用-1而不是1。 – Coincoin