answersLogoWhite

0


Best Answer

foreach char in string

push on to stack

create new string

foreach char in string

pop off and add to end of new string

if new string equals old string

palindrome

else not palindrome

//when you pop off the stack, the characters come off in reverse order, thus you have reversed the original string

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

You can use a stack to determine if a string is palindromic by pushing each character onto the stack, and then reading the string again while popping each saved character from the stack. If they match, then the string is palindromic.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can a stack determine if a string is a palindrome?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Code palindrome in c using queue and stuck?

/** C Program to Check String is Palindrome using Stack.*/#include #include void push(char);char pop();char stack[100];int top = -1;void main(){char str[100];int i, count = 0, len;printf("Enter string to check it is palindrome or not : ");scanf("%s", str);len = strlen(str);for (i = 0; i < len; i++){push(str[i]);}for (i = 0; i < len; i++){if (str[i] == pop())count++;}if (count == len)printf("%s is a Palindrome string\n", str);elseprintf("%s is not a palindrome string\n", str);}/* Function to push character into stack */void push(char c){stack[++top] = c;}/* Function to pop the top character from stack */char pop(){return(stack[top--]);}


Stack c language program of palindrome?

what ever you assume


Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


Bluej program-read a string and check if the given string is a palindrome?

import java.util.Scanner; public class Palindrome{ public static void main(String[] args){ String front; String back =""; char[] failure; String backwards; Scanner input=new Scanner(System.in); System.out.print("Enter a word: "); front=input.next(); front=front.replaceAll(" ", ""); failure=front.toCharArray(); for (int i=0; i&lt;failure.length; i++){ back=failure[i] + back; } if (front.equals(back)){ System.out.print("That word is a palindrome"); }else System.out.print("That word is not a palindrome"); }}


What is pallendrome in java?

palindrome in every language means same. it means on reversing a number or string, if we get the same number or string as the case may be ,then the number or string is called palindrome. eg: 1221,111,252 or LIRIL,MADAM etc .

Related questions

How do you determine if a given string is palindrome or not?

Reverse the string and compare it to the original. If they match, then it is a palindrome.


Code palindrome in c using queue and stuck?

/** C Program to Check String is Palindrome using Stack.*/#include #include void push(char);char pop();char stack[100];int top = -1;void main(){char str[100];int i, count = 0, len;printf("Enter string to check it is palindrome or not : ");scanf("%s", str);len = strlen(str);for (i = 0; i < len; i++){push(str[i]);}for (i = 0; i < len; i++){if (str[i] == pop())count++;}if (count == len)printf("%s is a Palindrome string\n", str);elseprintf("%s is not a palindrome string\n", str);}/* Function to push character into stack */void push(char c){stack[++top] = c;}/* Function to pop the top character from stack */char pop(){return(stack[top--]);}


What is Code for palindrome using stack?

poooda


What are examples of a palindrome program forward and backwards?

To check if a string is a palindrome, point to each end of the string and work inwards towards the middle. If the characters pointed at differ, the string is not a palindrome. When the pointers meet or cross each other, the string is a palindrome. Note that the string cannot contain whitespace or punctuation and comparisons must not be case-sensitive.


What is a string palindrome?

A string palindrome is some words that put together form a sentence. An example is "A man, a plan, a canal - Panama".


What is string palindrome?

A string palindrome is some words that put together form a sentence. An example is "A man, a plan, a canal - Panama".


Stack c language program of palindrome?

what ever you assume


Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


Program for palindrome in php?

You could use a function like this:function isPalindrome($string) {$string = strtolower($string);return (strrev($string) == $string) ? true : false;}and then to check a palindrome call an if statement like so:if(isPalindrome($test)) {echo $test.' is a palindrome';}else {echo $test.' is not a palindrome';}


Bluej program-read a string and check if the given string is a palindrome?

import java.util.Scanner; public class Palindrome{ public static void main(String[] args){ String front; String back =""; char[] failure; String backwards; Scanner input=new Scanner(System.in); System.out.print("Enter a word: "); front=input.next(); front=front.replaceAll(" ", ""); failure=front.toCharArray(); for (int i=0; i&lt;failure.length; i++){ back=failure[i] + back; } if (front.equals(back)){ System.out.print("That word is a palindrome"); }else System.out.print("That word is not a palindrome"); }}


Can 1111 be a palindrome?

If you mean the number 1,111 or simply 1111, this is a palindrome. A palindrome is a string or number that is spelled or written the same way forward and backward.


What is pallendrome in java?

palindrome in every language means same. it means on reversing a number or string, if we get the same number or string as the case may be ,then the number or string is called palindrome. eg: 1221,111,252 or LIRIL,MADAM etc .