-
Notifications
You must be signed in to change notification settings - Fork 6
/
Program1.c
65 lines (64 loc) · 856 Bytes
/
Program1.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <string.h>
int top = -1, top1 = -1;
#define MAX 100
char str[MAX];
char arr[MAX];
char rev[MAX];
int flag = 0;
int l, i;
void push(char c)
{
top++;
if (top == MAX)
printf("Stack full");
else
arr[top] = c;
}
void push1(char d)
{
top1++;
if (top1 == MAX)
printf("Stack full");
else
rev[top1] = d;
}
char pop()
{
return arr[top--];
}
char pop1()
{
return rev[top1--];
}
void isPalindrome(int m)
{
for (i = 0; i < m; i++)
{
char e = pop();
char f = pop1();
if (e == f)
flag = 1;
else
{
flag = 0;
break;
}
}
if (flag == 1)
printf("Palindrome\n");
else
printf("Not Palindrome\n");
}
int main()
{
printf("Enter the string : ");
scanf("%[^\n]", str);
l = strlen(str);
for (i = 0; i < l; i++)
push(str[i]);
for (i = l - 1; i >= 0; i--)
push1(str[i]);
isPalindrome(l);
return 0;
}