用线性表进行回文串的判断

本文介绍了一个使用 C 语言编写的简单程序,该程序能够从用户输入的一系列整数中判断是否为回文数。通过定义一个队列结构并利用其先进先出的特点,程序实现了对输入数字的前后对比。
#include<stdio.h>
main()
{    int b=1;
typedef struct{
    int *base;
    int front;
    int rear;
}squeue;
squeue q;
q.base=(int*)malloc(12*sizeof(int));
b=1;
    q.front=0;
    q.rear=0;
    printf("fen pei ok!\n");
    scanf("%d",&(q.base[q.rear]));
        printf("fen pei ok!\n");
    while(q.base[q.rear]!=0)
    {    q.rear++;
        scanf("%d",&(q.base[q.rear]));
    }
    q.rear--;
    while((q.rear>=q.front)&&(b>0))
    {    if(q.base[q.front]!=q.base[q.rear])
    {    b=-1;
    printf("%d***\n",q.base[q.rear]);
        printf("%d",q.base[q.front]);
        printf("----com---\n");
        }
        else{
            q.front++;
            q.rear--;
        }
    }
    if(b>0)
        printf("Yes!It is a hui wen shu !");
    else
        printf("No!It is not a hui wen shu!");
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值