/* program to check array of integers is palindrome or not using stack */
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h> // for bool type
#include"stack.h" // stack operation included here
#define MAX 20
int n;
struct stack s;
bool palindrome(int m,int A[])
{
int flag=0,j;
for(j=m;j<n;j++)
{
if(A[j]==pop(&s))
{
flag=1;
}
else
{
flag=0;
}
}
return flag;
}
int main()
{
int flag=0;
int i,j,A[10], item;
int ch;
initstack(&s);
printf("Enter no of integers :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter items:");
scanf("%d",&A[i]);
}
for(i=0;i<(n/2);i++)
{
push(&s,A[i]);
}
if(n%2==0)
{
if(palindrome(n/2,A))
{
printf("Palindrome\n");
}
else
{
printf("Not palindrome\n");
}
}
else
{
if(palindrome((n/2)+1,A))
{
printf("Palindrome\n");
}
else
{
printf("Not palindrome\n");
}
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h> // for bool type
#include"stack.h" // stack operation included here
#define MAX 20
int n;
struct stack s;
bool palindrome(int m,int A[])
{
int flag=0,j;
for(j=m;j<n;j++)
{
if(A[j]==pop(&s))
{
flag=1;
}
else
{
flag=0;
}
}
return flag;
}
int main()
{
int flag=0;
int i,j,A[10], item;
int ch;
initstack(&s);
printf("Enter no of integers :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter items:");
scanf("%d",&A[i]);
}
for(i=0;i<(n/2);i++)
{
push(&s,A[i]);
}
if(n%2==0)
{
if(palindrome(n/2,A))
{
printf("Palindrome\n");
}
else
{
printf("Not palindrome\n");
}
}
else
{
if(palindrome((n/2)+1,A))
{
printf("Palindrome\n");
}
else
{
printf("Not palindrome\n");
}
}
return 0;
}