编写一个串是否为回文的递归函数

来源:百度知道 编辑:UC知道 时间:2024/05/25 03:01:49
要是递归函数噢。。

int d_h(char *a,int s,int e) /*s是字符数组a的首元素下载,e是末元素下标*/
{
if (e-1==s&&a[s]==a[e]||s==e) return 1;
if (a[s]!=a[e]) return 0;
return (d_h(a,s+1,e-1));
}

调用示例:

//---------------------------------------------------------------------------

#include <stdio.h>
#include <string.h>

int d_h(char *a,int s,int e) /*s是字符数组a的首元素下载,e是末元素下标*/
{
if (e-1==s&&a[s]==a[e]||s==e) return 1;
if (a[s]!=a[e]) return 0;
return (d_h(a,s+1,e-1));
}

int main(int argc, char* argv[])
{
char a[]="abcedecba";
int i;
i=d_h(a,0,strlen(a)-1);
puts(i?"YES":"NO");
return 0;
}
//---------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int is_hw(const char *hw_ptr, int hw_len) {
if (hw_len == 0 |