diff --git a/a2/program.c b/a2/program.c index 495b26a..46bcc37 100644 --- a/a2/program.c +++ b/a2/program.c @@ -19,11 +19,9 @@ void push(char ch){ exit(0); } -char pop(){ - if(s.size > 0){ +void pop(){ + if(s.size >= 0) s.size--; - return (s.data[s.size]); - } else exit(0); } @@ -75,19 +73,13 @@ int main(){ char *b = calloc(l, sizeof(char)); for(i = 0; i < l; i++){ - //a[i] = gettop(); - // b[i] = right_pair(a[i]); - if(line[i] == '{' || line[i] == '(' || line[i] == '[' || line[i] == '<'){ push(line[i]); a[j] = gettop(); b[j] = right_pair(a[j]); j++; - //printf("%c", b[i]); } if(line[i] == '}' || line[i] == ')' || line[i] == ']' || line[i] == '>'){ - //a[i] = gettop(); - //b[i] = right_pair(a[i]); if(s.size == -1){ printf("Unexpected closing bracket %c in %d\n", line[i], i); return 0; @@ -100,10 +92,17 @@ int main(){ else{ pop(); } - } } - i = 0; + int begin = 0; + int end = strlen(b); + int h; + while(begin < end){ + h = b[begin]; + b[begin] = b[--end]; + b[end] = h; + } + if(s.size == -1){ printf("All brackets OK\n"); }