내가, 내가 디버깅 시도하고 볼 수있는 다음 코드 순차적 인 검색 비주얼 C++재귀 함수 오류 데브 - C++의
#include<iostream>
using namespace std;
int seqSearch(int list[], int length, int item)
{
int index = length-1;
if (index < 0)
return -1;
if (list[index] == item)
return (index);
else seqSearch(list, index, item);
} // end seqSearch
int main()
{
int const length = 10;
int item;
int list[10] = { 2, 3, 4, 5, 20, 40, 80, 45, 99, 0};
cout << "Please enter the value to be searched: ";
cin>> item;
if (seqSearch(list, length, item) == -1) cout << "Item not found." << endl;
else cout <<"Item found at position: " << seqSearch(list, length, item) << " of list *Note: (first index of list start at 0)" << endl;
system("pause");
return 0;
}
에서 그러나 항상 결과 0을 표시 ++ 데브 - C에서 완벽하게 실행 한 지수는 정확하지만 왜 그것은 0을 표시합니까? VC++과 Dev-C++의 차이점은 무엇입니까? 당신은 return 문을 놓쳤다
int seqSearch(int list[], int length, int item)
{
int index = length-1;
if (index < 0)
return -1;
if (list[index] == item)
return (index);
else return seqSearch(list, index, item);
}
재귀 순차 검색 ?? – SuperSaiyan
else else seqSearch (list, index, item);는 아무것도 반환하지 않습니다. 그것을'else return seqSearch (list, index, item);로 변경하십시오. – Vikas
대부분 문제와 관련이 없지만 [여기에 나열된 이유] (http://stackoverflow.com/tags/dev-c%2b%2b/info)에 대한 Dev-C++ 이외의 IDE를 조사하고 싶을 수 있습니다. . – Bart