Professional Documents
Culture Documents
other than $, w' = reverse(w)}*/ #include <stdio.h> /* Define standard input output routine */ #include <stdlib.h> #include <conio.h> /* Declaration of Stack data structure */ #define MAXSTACK 5 // Size of Stack typedef enum bool { FALSE, TRUE } BOOL; typedef struct stack{ int items[MAXSTACK]; int top; } STACK; /* Declaration of function prototypes */ void createStack(STACK *p); BOOL EmptyStack (STACK *p); BOOL FullStack (STACK *p); void InsertStack(STACK *p, int element); int RemoveStack(STACK *p);
printf("Enter a string: "); //Prompt user to input a string gets(str); //read the user's input
for(i = 0; str[i] != '$'; i++){ $ will act as mirror between if(str[i] != RemoveStack(&stck)){ //left and right char of the string flag = 0; break; } }//end of for
//Character
else
BOOL FullStack (STACK *p){ // Check if the stack is full return ((BOOL) (p->top >= MAXSTACK - 1)); }//end of BOOL FullStack
/* Insert an item into a stack t or display an error message if t is full */ void InsertStack(STACK *p, int element){ if(FullStack(p)){ printf("stack is full !\n"); } else{
/* Remove an item from a stack t or display an error message if t is empty */ int RemoveStack(STACK *p){ if(EmptyStack(p)){ printf("stack empty !\n"); } else if (p->top > 0){ return (p->items[(p->top)--]); } }//end of void pop