Sunday, August 2, 2009

How to write a C progamming language that uses a stack to determine if a string palindrome.?

palindrome is a word or phrase which reads the same in both directions.the program should ignore spaces %26amp; punctuation. example or word palindrome is:RACECAR, DEED, LEVEL,PIP,ROTOR,CIVIC,POP, MADAM,EYE,NUN,RADAR,TOOT.Example of phrase palindrome is:LIVE EVIL %26amp; STRAW WARTS. Can anyone help me to write the C programming URGENT.TQ

How to write a C progamming language that uses a stack to determine if a string palindrome.?
It says he has to do it using a stack. Basically you have to create some sort of stack data structure if you don't have one at your disposal. I would just use a linked list and then you need to implement the push, pop, and peek functions that manipulate your linked list. Next you take the word and push each character onto the stack starting at the first character going towards the end. Then you iterate through the input string starting at the end and going towards the beginning. At each character you pop off one character from the stack and compare it to the current character. If they are not equal exit your loop because the input is not a palindrome.
Reply:You need two strings arrays str1[] and str1[]


resverse the str1[] into str2[] and check them for equlance


if(strcmp(str1, str2)==0)


printf("\n String is Plaindrome");


else


printf("\n Not a Palindrome");





strcmp() is used to comapre two strings, it returns 0 if both strings are equal.


No comments:

Post a Comment