answersLogoWhite

0

  1. /*
  2. * C Program to Check String is Palindrome using Stack.
  3. */
  4. #include
  5. #include
  6. void push(char);
  7. char pop();
  8. char stack[100];
  9. int top = -1;
  10. void main()
  11. {
  12. char str[100];
  13. int i, count = 0, len;
  14. printf("Enter string to check it is palindrome or not : ");
  15. scanf("%s", str);
  16. len = strlen(str);
  17. for (i = 0; i < len; i++)
  18. {
  19. push(str[i]);
  20. }
  21. for (i = 0; i < len; i++)
  22. {
  23. if (str[i] == pop())
  24. count++;
  25. }
  26. if (count == len)
  27. printf("%s is a Palindrome string\n", str);
  28. else
  29. printf("%s is not a palindrome string\n", str);
  30. }
  31. /* Function to push character into stack */
  32. void push(char c)
  33. {
  34. stack[++top] = c;
  35. }
  36. /* Function to pop the top character from stack */
  37. char pop()
  38. {
  39. return(stack[top--]);
  40. }
User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

Circular queue in linear data structure?

The queue is a linear data structure where operations of insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. A circular queue is similar to the normal queue with the difference that queue is circular queue ; that is pointer rear can point to beginning of the queue when it reaches at the end of the queue. Advantage of this type of queue is that empty location let due to deletion of elements using front pointer can again be filled using rear pointer.


A code for find minimum queue in c language?

To find the minimum element in a queue using C, you can traverse the queue elements, comparing each to track the minimum value. Here's a simple implementation assuming a circular queue structure: #include &lt;stdio.h&gt; #include &lt;limits.h&gt; #define MAX 100 typedef struct { int items[MAX]; int front, rear; } Queue; int findMin(Queue* q) { if (q-&gt;front == -1) return INT_MAX; // Queue is empty int min = INT_MAX; for (int i = q-&gt;front; i != q-&gt;rear; i = (i + 1) % MAX) { if (q-&gt;items[i] &lt; min) { min = q-&gt;items[i]; } } // Check the rear element if (q-&gt;items[q-&gt;rear] &lt; min) { min = q-&gt;items[q-&gt;rear]; } return min; } This function iterates through the elements of the queue to find and return the minimum value.


Program to check palindrome using recursion?

#include &lt;stdio.h&gt; #include &lt;conio.h&gt; void main() { int num,rev=0,m,r; clrscr(); printf("enter any number"); scanf("%d",&amp;num); m=num; while(num&gt;0) { r=num%10; rev=rev*10+r; num=num/10; } if(rev==m) printf("given number is palindrome"); else printf("given number is not palindrome"); getch(); } this is the answer.


Write a program in c language to reverse elements of a queue?

There are many ways to reverse the order of the elements in a queue. Provided that you have access to the implementation of the queue, it is of course easy to read the elements from the tail end rather than the front end, thus reversing the elements. However, considering the queue as a black box, and assuming the queue only allows for its characteristic operations (removal of head element, addition to tail), the best method to reverse the elements in a queue to engage a stack. You'd remove the elements from the queue (always reading the head of the queue), and push each element onto the stack. When the queue is empty, you reverse that process: pop each element from the stack until it is empty, and add each element in this order to the end of the queue. Your queue will have the exact same elements as in the beginning, but in reverse order. The exact implementation of this in C, or in any other programming language, is trivial, but the exact source code depends on the implementation of queue and stack containers. Following is pseudocode: Queue&lt;Item&gt; reverse (Queue&lt;Item&gt; queue) { Stack&lt;Item&gt; stack; Item item; while (queue.remove(&amp;item)) { stack.push(item); } while(stack.pop(&amp;item)) { queue.add(item); } return queue; }


Write a java program to find weather a given string is a palindrome or not?

import java.io.*; class StringPalindrome { static void main()throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br= new BufferedReader(isr); System.out.println("Enter a word"); String input=br.readLine(); int x= input.length(); char ans; String fin=""; for(int y=x-1; y&gt;=0; y--) { ans=input.charAt(y); fin=fin+ans; } System.out.println("The reverse is " + fin); if(fin.equalsIgnoreCase(input)) { System.out.println("Palindrome"); } else { System.out.println("Not a palindrome"); } } }

Related Questions

What is Code for palindrome using stack?

poooda


Circular queue in linear data structure?

The queue is a linear data structure where operations of insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. A circular queue is similar to the normal queue with the difference that queue is circular queue ; that is pointer rear can point to beginning of the queue when it reaches at the end of the queue. Advantage of this type of queue is that empty location let due to deletion of elements using front pointer can again be filled using rear pointer.


How can footstool be considered a Palindrome?

in morse code


What is the palindrome that indicates a cry for help?

SOS, the international Morse code distress signal, is a palindrome.


What is the code for level 6 in cartoon hero?

palindrome


How do you code a palindrome in VB?

Private Sub Command1_Click() string1 = Text1.Text string2 = StrReverse(string1) result = StrComp(string1, string2, vbTextCompare) If result = 0 Then MsgBox string2 &amp; " is a palindrome..." Else MsgBox string1 &amp; " is not a palindrome..." End If End Sub


Sql code for palindrome checking in sql?

FieldName = REVERSE(FieldName) FieldName = REVERSE(FieldName)


A code for find minimum queue in c language?

To find the minimum element in a queue using C, you can traverse the queue elements, comparing each to track the minimum value. Here's a simple implementation assuming a circular queue structure: #include &lt;stdio.h&gt; #include &lt;limits.h&gt; #define MAX 100 typedef struct { int items[MAX]; int front, rear; } Queue; int findMin(Queue* q) { if (q-&gt;front == -1) return INT_MAX; // Queue is empty int min = INT_MAX; for (int i = q-&gt;front; i != q-&gt;rear; i = (i + 1) % MAX) { if (q-&gt;items[i] &lt; min) { min = q-&gt;items[i]; } } // Check the rear element if (q-&gt;items[q-&gt;rear] &lt; min) { min = q-&gt;items[q-&gt;rear]; } return min; } This function iterates through the elements of the queue to find and return the minimum value.


Program to check palindrome using recursion?

#include &lt;stdio.h&gt; #include &lt;conio.h&gt; void main() { int num,rev=0,m,r; clrscr(); printf("enter any number"); scanf("%d",&amp;num); m=num; while(num&gt;0) { r=num%10; rev=rev*10+r; num=num/10; } if(rev==m) printf("given number is palindrome"); else printf("given number is not palindrome"); getch(); } this is the answer.


How do you create a FIFO collection using Java?

There's a great class called LinkedList that implements the Queue interface. To get an instance of it, use the following code snippet: import java.util.*; Queue queue = new LinkedList&lt;T&gt;(); where T is the type of the objects that will go in the queue. Remember the parentheses, as they drove me crazy during one memorable day working out why exactly that same line, minus the parentheses, kept on throwing me a rather unintelligible error. Example: Queue&lt;String&gt; q = new java.util.LinkedList&lt;String&gt;() q.add("a") q.add("b") q.add("c") Calling q.getFirst() returns the value "a". Likewise, to create a Last-in first out (LIFO) collection, you use a Stack (java.util.Stack).


Write a program in c language to reverse elements of a queue?

There are many ways to reverse the order of the elements in a queue. Provided that you have access to the implementation of the queue, it is of course easy to read the elements from the tail end rather than the front end, thus reversing the elements. However, considering the queue as a black box, and assuming the queue only allows for its characteristic operations (removal of head element, addition to tail), the best method to reverse the elements in a queue to engage a stack. You'd remove the elements from the queue (always reading the head of the queue), and push each element onto the stack. When the queue is empty, you reverse that process: pop each element from the stack until it is empty, and add each element in this order to the end of the queue. Your queue will have the exact same elements as in the beginning, but in reverse order. The exact implementation of this in C, or in any other programming language, is trivial, but the exact source code depends on the implementation of queue and stack containers. Following is pseudocode: Queue&lt;Item&gt; reverse (Queue&lt;Item&gt; queue) { Stack&lt;Item&gt; stack; Item item; while (queue.remove(&amp;item)) { stack.push(item); } while(stack.pop(&amp;item)) { queue.add(item); } return queue; }


What does error code P0752 mean?

Trouble code P0752 means:Shift solenoid A stuck on