typedef struct istack
{
int data[STACK_SIZE];
int top;
} IStack;
void initialize(IStack *sp)
{
sp -> top = EMPTY_STACK;
}
int push(IStack *sp, int value)
{
if(sp -> top == (STACK_SIZE - 1))
return FAILURE;
sp -> top++;
sp -> data[sp -> top] = value;
return SUCCESS;
}
int pop(IStack *sp, int *value)
{
if(sp -> top == EMPTY_STACK)
return FAILURE;
*value = sp -> data[sp -> top];
sp -> top--;
return SUCCESS;
}
int peek(IStack *sp, int *value)
{
if(sp -> top == EMPTY_STACK)
return FAILURE;
*value = sp -> data[sp -> top];
return SUCCESS;
}
void display(const IStack *sp)
{
int i;
if(sp -> top == EMPTY_STACK)
{
printf("\n Stack is empty");
return;
}
printf("\n Displaying stack:");
for(i = sp -> top ; i >= 0 ; i--)
printf("\n%d", sp -> data[i]);
printf("\n Number of elements: %d",(sp -> top + 1));
}
{
int data[STACK_SIZE];
int top;
} IStack;
void initialize(IStack *sp)
{
sp -> top = EMPTY_STACK;
}
int push(IStack *sp, int value)
{
if(sp -> top == (STACK_SIZE - 1))
return FAILURE;
sp -> top++;
sp -> data[sp -> top] = value;
return SUCCESS;
}
int pop(IStack *sp, int *value)
{
if(sp -> top == EMPTY_STACK)
return FAILURE;
*value = sp -> data[sp -> top];
sp -> top--;
return SUCCESS;
}
int peek(IStack *sp, int *value)
{
if(sp -> top == EMPTY_STACK)
return FAILURE;
*value = sp -> data[sp -> top];
return SUCCESS;
}
void display(const IStack *sp)
{
int i;
if(sp -> top == EMPTY_STACK)
{
printf("\n Stack is empty");
return;
}
printf("\n Displaying stack:");
for(i = sp -> top ; i >= 0 ; i--)
printf("\n%d", sp -> data[i]);
printf("\n Number of elements: %d",(sp -> top + 1));
}
No comments:
Post a Comment
kiss on google ads if you are anonymous because your ip is trackable.thank you.
......from.admin