Stack using array

#define size 10
struct stack {
   int s[size];
   int top;
} st;
 
int stfull() {
   if (st.top >= size - 1)
      return 1;
   else
      return 0;
}
 
void push(int item) {
   st.s[st.top++] = item;
}
 
int stempty() {
   if (st.top == -1)
      return 1;
   else
      return 0;
}
 
int pop() {
   int item;
   item = st.s[st.top];
   st.top--;
   return (item);
}
 
void display() {
   int i;
   if (stempty())
      printf("\nStack Is Empty!");
   else {
      for (i = st.top; i >= 0; i--)
         printf("\n %d", st.s[i]);
   }
}

Leave a comment