栈的回文判断
作者:互联网
#include<stdio.h>
#include<stdlib.h>
int tail=0,top=0;
typedef struct Stack
{
char data;
struct Stack *next;
}Stack;
Stack *CreateNode_Head()
{
Stack *headNdoe=(Stack *)malloc(sizeof(Stack));
headNdoe->next=NULL;
headNdoe->data=NULL;
return headNdoe;
}
Stack *CreateNode(char data)
{
Stack *newNode=(Stack *)malloc(sizeof(Stack));
newNode->data=data;
newNode->next=NULL;
return newNode;
}
void Stack_insert(Stack *headNode,char data)
{
Stack *newNode=CreateNode(data);
newNode->next=headNode->next;
headNode->next=newNode;
top++;
}
void printf_stack(Stack *headNode)
{
Stack *p=headNode;
while(p->next!=NULL)
{
printf("%c ",p->next->data);
p=p->next;
}
}
void Judge_Palindrome_Number(Stack *headNode)
{
int i=0,k,j;
char arr[top];
Stack *p=headNode;
while(p->next!=NULL)
{
arr[i++]=p->next->data;
p=p->next;
}
for(int k=0;k<top/2+1;k++)
{
if(arr[k]!=arr[top-k-1])
{
printf("不是回文数");
return;
}
}
printf("是回文数");
}
int main()
{
char data;
Stack *head=CreateNode_Head();
while((data=getchar())!='\n')
{
Stack_insert(head,data);
}
//printf_stack(head);
//printf("%d",top);
Judge_Palindrome_Number(head);
}
标签:判断,next,headNode,printf,newNode,data,Stack,回文 来源: https://blog.csdn.net/qq_53737502/article/details/121415142