rendered paste bodyStack .h/.c
------------------------------------------------------
stack.h
-------
#define SIZE 7
#define TYPE char
typedef enum{FALSE,TRUE} bul;
typedef struct stack
{
TYPE ar[SIZE];
int top;
}stack;
void stack_init(stack *s);
bul stack_empty(stack s);
bul stack_full(stack s);
bul push(stack *s,TYPE item);
bul pop(stack *s,TYPE *item);
stack.c
-------
#include "stack.h"
void stack_init(stack *s)
{
s->top = -1;
}
bul stack_empty(stack s)
{
return (s.top == -1)?TRUE:FALSE;
}
bul stack_full(stack s)
{
return (s.top == SIZE-1)?TRUE:FALSE;
}
bul push(stack *s, TYPE item)
{
if(!stack_full(*s))
{
s->ar[++(s->top)] = item;
return TRUE;
}
return FALSE;
}
bul pop (stack *s,TYPE *item)
{
if(!stack_empty(*s))
{
*item = s->ar[s->top--];
return TRUE;
}
return FALSE;
}
------------------------------------------------------
//MAIN
------------------------------------------------------
#include <stdio.h>
#include "stack.h"
void main()
{
stack s1;
stack s2;
int i;
int flag=1;
TYPE ch,ch1;
stack_init(&s1);
stack_init(&s2);
while(!stack_full(s1))
{
printf("Enter a char\n");
scanf("%c",&ch);
push(&s1,ch);
}
pop(&s1,&ch);
while(ch!='C'&&!stack_empty(s1))
{
push(&s2,ch);
pop(&s1,&ch);
}
pop(&s1,&ch);
if(ch == 'C')
while(!stack_empty(s1)&&!stack_empty(s2)&&flag)
{
pop(&s1,&ch);
pop(&s2,&ch1);
(ch != ch1)?(flag=0):0;
}
else
printf("The string is invalid");
(flag)?(printf("The string is good")):(printf("The string is invalid"));
}