#define max_size 10000 int stack[max_size]; int top = -1; void push(char data) { if (top == max_size-1) { printf("Stack Overflow\n"); return; } else { stack[++top] = data; } } int isempty() { if (top <= -1) { return 1; } return 0; } int pop() { if (isempty()) { printf("Stack Underflow\n"); return -1; } return stack[top--]; } bool isValid(char * s) { while(*s!='\0') { if(*s == '(' || *s == '{' || *s == '[') { push(*s); } else if(*s == ')' || *s == '}' || *s == ']') { if(isempty() || (*s == ')' && pop() != '(') || (*s == '}' && pop() != '{') || (*s == ']' && pop() != '[')) { return 0; } } s++; } if(isempty()) { return 1; } else { return 0; } }#define max_size 10000 int stack[max_size]; int top = -1; void push(char data) { if (top == max_size-1) { printf("Stack Overflow\n"); return; } else { stack[++top] = data; } } int isempty() { if (top <= -1) { return 1; } return 0; } int pop() { if (isempty()) { printf("Stack Underflow\n"); return -1; } return stack[top--]; } bool isValid(char * s) { while(*s!='\0') { if(*s == '(' || *s == '{' || *s == '[') { push(*s); } else if(*s == ')' || *s == '}' || *s == ']') { if(isempty() || (*s == ')' && pop() != '(') || (*s == '}' && pop() != '{') || (*s == ']' && pop() != '[')) { return 0; } } s++; } if(isempty()) { return 1; } else { 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