Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 50
- int top = -1, front = 0;
- int stack[MAX];
- void push(char);
- void pop();
- int main()
- {
- int i, choice;
- char str[MAX], b;
- while (1)
- {
- printf("\nMasukkan String\n");
- scanf("%s", str);
- for (i = 0; str[i] != '\0';i++)
- {
- b = str[i];
- push(b);
- }
- for (i = 0;i < (strlen(s) / 2);i++)
- {
- if (stack[top] == stack[front])
- {
- pop();
- front++;
- }
- else
- {
- printf("%s bukan palindrom\n", str);
- break;
- }
- }
- if ((strlen(s) / 2) == front)
- printf("%s adalah palindrom\n", str);
- front = 0;
- top = -1;
- }
- }
- /* untuk memasukkan data ke dalam stack */
- void push(char a)
- {
- top++;
- stack[top] = a;
- }
- /* untuk menghapus elemen didalam stack */
- void pop()
- {
- top--;
- }
Advertisement
Add Comment
Please, Sign In to add comment