#include <stdio.h> #include <stdlib.h> struct stack{ int size; int top; int *arr; }; int isEmpty(struct stack *ptr){ if(ptr->top==-1){ return 1; } return 0; } int isFull(struct stack*ptr){ if(ptr->top == ptr->size-1){ return 1; } return 0; } int main() { // struct stack s; // s.size=80; // s.top=-1; // s.arr = (int*)malloc(s.size*sizeof(int)); struct stack *s; s->size=80; s->top=-1; s->arr = (int*)malloc(s->size*sizeof(int)); s->arr[0]=7; s->top++; if(isEmpty(s)){ printf("stack is empty"); } else{ printf("stack is full"); } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter