#define MAX 1000 /* only 1000 elements can be stored in the stack*/
# define TRUE 1
# define FALSE 0
typedef int stack_data;
struct stack_inf{
int top;
stack_data stack_elements[MAX];
};
typedef struct stack_inf stack;
stack s;
void create(stack *s)
{
s->top=-1;
return;
}
int isempty (stack *s)
{
if (s->top == -1)
return(TRUE);
else
return(FALSE);
}
int isfull (stack *s)
{
if (s->top == (MAX -1))
return(TRUE);
else
return(FALSE);
}
stack_data pop (stack *s)
{
int t;
stack_data ret;
if (isempty(s))
printf(“The stack is empty\n”);
else
{
t = s->top;
ret=s->stack_elements[t];
s->top - -;
}
return(ret);
}
void push (stack *s, stack_data x)
{
if (isfull(s))
printf(“Stack is FULL ! No insertion possible\n”);
else
{
++s->top;
s->stack_elements[s->top]=x;
}
}
No comments:
Post a Comment