#define MAXSTACK 5
typedef struct
{
int sp;
int Data[MAXSTACK];
}STACK;
void Initialize(STACK *s);
int push(STACK *s,int item);
int pop(STACK *s,int *ret);
int full(STACK *s);
int empty(STACK *s);
void Initialize(STACK *s)
{
s->sp=0;
}
int push(STACK *s,int item)
{
if(full(s))
{
printf("Stack is full !!!\n");
return 0;
}
else
{
printf("\tpush -> %d\n",item);
s->Data[s->sp++]=item;
}
return 1;
}
int full(STACK *s)
{
if(s->sp==MAXSTACK)
return 1;
return 0;
}
...................................................
#include
#define MAXSTACK 5
typedef struct
{
int sp;
int Data[MAXSTACK];
}STACK;
void Initialize(STACK *s);
int push(STACK *s,int item);
int pop(STACK *s,int *ret);
int full(STACK *s);
int empty(STACK *s);
void Initialize(STACK *s)
{
s->sp=0;
}
int push(STACK *s,int item)
{
if(full(s))
{
printf("Stack is full !!!\n");
return 0;
}
else
{
printf("\tpush -> %d\n",item);
s->Data[s->sp++]=item;
}
return 1;
}
int full(STACK *s)
{
if(s->sp==MAXSTACK)
return 1;
return 0;
}
................................................
No comments:
Post a Comment