-
Notifications
You must be signed in to change notification settings - Fork 0
/
检测回文.cpp
47 lines (43 loc) · 955 Bytes
/
检测回文.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
#include<stdlib.h>
//基于堆栈和队列的回文检测
typedef struct linknode
{ char data;
struct linknode *next;
}node;
node *head;
int n=0;
//以下为检测回文主程序
int main()
{
node *top,*last,*a3;
node *p,*s;
int l;
char x;
n=0;
head=(node*)malloc(sizeof(node));
last=(node*)malloc(sizeof(node));
p=last;
scanf("%c",&x);
s=(node*)malloc(sizeof(node));
n++;
s->data=x;
s->next=NULL;
top=s;
scanf("%c",&x);
while(x!='#') //从栈顶输出(先进的先出)
{
s=(node*)malloc(sizeof(node));
n++;
s->data=x;
s->next=top;
top=s;
scanf("%c",&x);
}
a3=top;
while(a3->next!=NULL) //输出堆栈结果
{
a3=a3->next;
printf("%c",a3->data);
}
}