1 of 1 15 points) Palindrome Detector. A palindrome is a phrase that reads the P
ID: 3778702 • Letter: 1
Question
1 of 1 15 points) Palindrome Detector. A palindrome is a phrase that reads the Pi same ronwards as it does backwards. For example, "a man, a plan, a canal, Panama is a palindrome. Write a program that uses a stack to check for palindromes in each line of a text file. Try your program on the example text file "palindromes txt".Your program should output the palindromes that it finds in the document. For example: FindPalindromes( palindromes.txt") will display "a man, a plan, a canal, Panama" is a palindrome. "Don't nod" is a palindrome. "Taco Cat!" is a palindrome. Using only a fixed number of stacks, the stack ADT functions, and a fixed number of int and char variables, write the function FindPalindromes to display all palindromes found in a given text file. Feel free to use either a LinkedList or an array to implement the Stack. What is the complexity of your function?Explanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,len,flag=1;
char a[20];
cout<<“Enter a string:”;
cin>>a;
for(len=0;a[len]!=’’;++len);
for(i=0,j=len-1;i<len/2;++i,–j)
{
if(a[j]!=a[i])
flag=0;
}
if(flag==1)
cout<<“nThe string is Palindrome”;
else
cout<<“nThe string is not Palindrome”;
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.