我在大學被分配了這個練習,但我不知道如何實現遞歸結構(代碼中的「???」)。在if循環中,我應該將數組中的第一個字符與最後一個字符進行匹配,然後應用遞歸以便到達中央字符,但是我不知道如何設置代碼。主要功能代碼完美編譯。用於識別迴文字符數組的遞歸函數
#include <iostream>
using namespace std;
const int DIM = 8;
bool is_palindrome (char* first, char* last)
{
if (first == last)
{
???
}
else
return false;
}
int main()
{
char a[DIM] = {'i','n','g','e','g','n','i','\0'};
char *first = &a[DIM] + 1;
char *last = &a[DIM] -1;
if (is_palindrome(first, last))
cout << " the char array is palindrome ";
else
cout << " the char array is not palindrome ";
return 0;
}
非常感謝! :) –
作業==不給予免費的迴應... –
@MichaelDorgan我不要求免費的迴應,我問的建議。 –