/* save as "get_Minimum.h" file */
#include<stdio.h>
#include<stdlib.h>
#define MAX 10
struct stack
{
int arr[MAX];
int getMin[MAX];
int top;
};
void initstack(struct stack *s)
{
s->top=-1;
}
void push(struct stack *s,int item)
{
if(s->top==MAX-1)
{
printf("stack is full\n");
}
else
{
if(s->top==-1)
{
s->top++;
s->getMin[s->top]=item;
s->arr[s->top]=item;
}
else if(item<=(s->getMin[s->top]))
{
printf("push in else if is %d \n",s->getMin[s->top]);
s->top++;
s->getMin[s->top]=item;
s->arr[s->top]=item;
}
else
{
int x=s->getMin[s->top];
printf("push in else is %d\n",s->getMin[s->top]);
s->top++;
s->arr[s->top]=item;
s->getMin[s->top]=x;
}
}
}
int pop(struct stack *s)
{
int data,min;
if(s->top==-1)
{
printf("Stack is empty.\n");
exit(1);
}
else
{
data=s->arr[s->top];
min=s->getMin[s->top];
s->top--;
printf("\n minimum is %d \n",min);
return data;
}
}
#include<stdio.h>
#include<stdlib.h>
#define MAX 10
struct stack
{
int arr[MAX];
int getMin[MAX];
int top;
};
void initstack(struct stack *s)
{
s->top=-1;
}
void push(struct stack *s,int item)
{
if(s->top==MAX-1)
{
printf("stack is full\n");
}
else
{
if(s->top==-1)
{
s->top++;
s->getMin[s->top]=item;
s->arr[s->top]=item;
}
else if(item<=(s->getMin[s->top]))
{
printf("push in else if is %d \n",s->getMin[s->top]);
s->top++;
s->getMin[s->top]=item;
s->arr[s->top]=item;
}
else
{
int x=s->getMin[s->top];
printf("push in else is %d\n",s->getMin[s->top]);
s->top++;
s->arr[s->top]=item;
s->getMin[s->top]=x;
}
}
}
int pop(struct stack *s)
{
int data,min;
if(s->top==-1)
{
printf("Stack is empty.\n");
exit(1);
}
else
{
data=s->arr[s->top];
min=s->getMin[s->top];
s->top--;
printf("\n minimum is %d \n",min);
return data;
}
}