stack : stack means "last in first out".(LIFO)
op:stack is fullthe deleted elent is = 60x
#include<stdio.h>
#define max 5
struct node
{
int a[max];
int top;
};
void initialize(struct node*);
void push(struct node*,int);
int pop(struct node*);
main()
{
struct node s;
int i;
initialize(&s);
push(&s,20);
push(&s,30);
push(&s,40);
push(&s,50);
push(&s,60);
push(&s,70);
i=pop(&s);
printf("the deleted elent is = %d\n",i);
}
void initialize(struct node *s)
{ s->top = -1;
}
void push(struct node *s,int num)
{
if(s->top == max-1)
{
printf("stack is full\n");
}
else
{
s->top++; s->a[s->top] = num;
}
}
int pop(struct node *s)
{
int d; if(s->top == -1)
{
printf("stack is empty\n");
}
else
{
d = s->a[s->top]; s->top--; return d; }
}
op:stack is fullthe deleted elent is = 60x
0 comments: