您当前的位置: 首页 > 

川川菜鸟

暂无认证

  • 2浏览

    0关注

    969博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

回文判断

川川菜鸟 发布时间:2021-05-17 01:44:43 ,浏览量:2

//群:970353786
#include"stdio.h"
#include"stdlib.h"
typedef char ElemType;
typedef struct stnode
{
	ElemType data;
	struct stnode* next;
}StNode, * LinkStack;
int huiwen(char str[])
{
	int i = 0;
	char ch;
	StNode* sl = NULL, * p;
	while ((ch = str[i++]) != '\0')
	{
		p = (StNode*)malloc(sizeof(StNode));//给内存
		p->data = ch;
		p->next = sl;
		sl = p;
	}
	i = 0;
	while (sl != NULL)
	{
		p = sl;
		ch = p->data;
		sl = sl->next;
		free(p);//释放内存
		if (ch != str[i++])
			return 0;
	}
	return 1;
}
void main()
{
	char string[30];//最长为30
	int hw;
	printf("请输入字符串:");
	gets_s(string);
	hw = huiwen(string);
	if (hw) printf("字符串是回文.");
	else printf("字符串不是回文");
}

关注
打赏
1665165634
查看更多评论
立即登录/注册

微信扫码登录

0.0475s