document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX 50
  5.  
  6. int top = -1, front = 0;
  7. int stack[MAX];
  8. void push(char);
  9. void pop();
  10.  
  11. int main()
  12. {
  13.     int i, choice;
  14.     char str[MAX], b;
  15.     while (1)
  16.     {
  17.            
  18.             printf("\\nMasukkan String\\n");
  19.             scanf("%s", str);
  20.             for (i = 0; str[i] != \'\\0\';i++)
  21.             {
  22.                 b = str[i];
  23.                 push(b);
  24.             }
  25.             for (i = 0;i < (strlen(s) / 2);i++)
  26.             {
  27.                 if (stack[top] == stack[front])
  28.                 {
  29.                     pop();
  30.                     front++;
  31.                 }
  32.                 else
  33.                 {
  34.                     printf("%s bukan palindrom\\n", str);
  35.                     break;
  36.                 }
  37.             }
  38.             if ((strlen(s) / 2) ==  front)
  39.                 printf("%s adalah palindrom\\n",  str);
  40.             front  =  0;
  41.             top  =  -1;
  42.        
  43.         }
  44.     }
  45.  
  46.  
  47. /* untuk memasukkan data ke dalam stack */
  48. void push(char a)
  49. {
  50.     top++;
  51.     stack[top] = a;
  52. }
  53.  
  54. /* untuk menghapus elemen didalam stack  */
  55. void pop()
  56. {
  57.     top--;
  58. }
');