Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Check Expression with Stack
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_STACK_SIZE 100 #define MAX_STRING_SIZE 100 typedef int element; typedef struct { element *data; int capacity; int top; }StackType; void init_stack(StackType *s) { s->top = -1; s->capacity = 1; s->data = (element *) malloc(s->capacity * sizeof(element)); } int is_empty(StackType *s) { return (s->top == -1); } int is_full(StackType *s) { return(s->top == MAX_STACK_SIZE - 1 ); } void push(StackType *s,element item) { if(is_full(s)) { s->capacity *= 2; s->data = (element *) realloc(s->data,s->capacity * sizeof(element)); } s->data[++(s->top)] = item; } element pop(StackType *s) { if(is_empty(s)) { fprintf(stderr,"스택이 비었습니다."); exit(1); } else return s->data[(s->top)--]; } int check_matching(char *expr) { StackType *s; s = (StackType *) malloc(sizeof(StackType)); char ch,open_ch; int i, n = strlen(expr); init_stack(s); for(i = 0; i < n; i++){ ch = expr[i]; switch (ch) { case '(': case '{': case '[': push(s,ch); break; case ')': case '}' : case ']': if(is_empty(s)) return 0; else { open_ch = pop(s); if((open_ch == '(' && ch != ')') || (open_ch == '{' && ch != '}') || (open_ch == '[' && ch != ']')) { return 0; } break; } } } if (!is_empty(s)) return 0; return 1; } int main(void) { char *p = "{ A[(i+1))]=0; }"; if (check_matching(p) == 1) printf("%s 괄호검사성공\n",p); else printf("%s 괄호검사실패\n",p); return 0; }
cl.exe
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 1,21 sec, absolute running time: 0,32 sec, absolute service time: 1,56 sec
edit mode
|
history
|
discussion