answersLogoWhite

0


Best Answer
  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

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Code palindrome in c using queue and stuck?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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.


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"); } } }


What is the algorithm for inserting values into a queue in c plus plus?

A queue usually infers first in first out (FIFO), therefore new values will need to be inserted after the last node (the tail node) and the queue must maintain pointers to both the head node for extraction and the tail node for insertion, and each node must maintain a pointer to the next node in the queue (singly-linked list). The following code provides a bare-bones implementation of a singly-linked FIFO list, where each value is an integer. In real-life you'd use one of the built-in class templates, otherwise you'd have to re-write the same code to cater for all the different value types you might want to place in a queue (or create your own class template). However, the example serves to show the algorithm that is used to insert new values to the end of a queue. It does not show how to extract the first node from the queue. #include &lt;iostream&gt; using namespace std; class Node { public: Node( int iValue ):m_iValue( iValue ),m_pNext( NULL ){} ~Node(){ if( m_pNext ) delete m_pNext; } Node * GetNext()const{ return m_pNext; } void SetNext(Node * pNext ){ m_pNext = pNext; } int GetValue()const{ return m_iValue; } private: Node * m_pNext; int m_iValue; }; class Queue { public: Queue():m_pFirst(NULL),m_pLast(NULL){} ~Queue(){ if( m_pFirst ) delete m_pFirst; } Node * GetFirst()const{ return m_pFirst; } Node * GetLast()const{ return m_pLast; } void Insert( int iValue ); void ShowAll()const; private: Node * m_pFirst; Node * m_pLast; }; void Queue::Insert( int iValue ) { Node * pNew = new Node( iValue ); if( m_pLast ) m_pLast-&gt;SetNext( pNew ); else m_pFirst = pNew; m_pLast = pNew; } void Queue::ShowAll() const { Node * pNode = m_pFirst; while( pNode ) { cout &lt;&lt; pNode-&gt;GetValue(); if( pNode != m_pLast ) cout &lt;&lt; ", "; pNode = pNode-&gt;GetNext(); } cout &lt;&lt; endl &lt;&lt; endl; } int main() { Queue queue; queue.Insert( 2 ); queue.Insert( 1 ); queue.Insert( 3 ); queue.ShowAll(); return( 0 ); }

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?

The palindrome that indicates a cry for help is &quot;A Santa at NASA.&quot;


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)


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).


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; }


What does error code P0752 mean?

Trouble code P0752 means:Shift solenoid A stuck on


What is the ar code to fix Pokemon platinum when you are stuck in a wall?

Your an idiot, you actually got stuck in a wall