Guest User

Untitled

a guest
Nov 14th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<string.h>
  4. #define MAX 100
  5. char stack[MAX];
  6. int top=-1;
  7. void push(char s);
  8. void pop();
  9. int main()
  10. { char s[100];
  11. int front=0,flag=0;
  12. printf("Enter the string\n");
  13. gets(s);
  14. for(int i=0;i<strlen(s);i++)
  15. push(s[i]);
  16. printf("Reverse of the string is \n");
  17. pop();
  18. for(int i=0;i<(strlen(s)/2);i++)
  19. {
  20. if(stack[front]==' ')
  21. front++;
  22. if(stack[top]==' ')
  23. top--;
  24. if(stack[front]!=stack[top])
  25. {flag=1;
  26. break;
  27. }front++;
  28. top--;
  29. }
  30. if(flag==0)
  31. {
  32. printf("\nstring is a palindrome");
  33. }
  34. else
  35. printf("\nstring is not a palindrome");
  36. return 0;
  37. }
  38. void push(char s)
  39. {
  40. top++;
  41. stack[top]=s;
  42. return;
  43. }
  44. void pop()
  45. {int t=top;
  46. for(int i=t;i>-1;i--)
  47. printf("%c",stack[i]);
  48. return;
  49. }
Add Comment
Please, Sign In to add comment