This commit is contained in:
Maryna Kravtsova 2020-10-21 14:46:30 +02:00
parent bef9c5185a
commit a2310e4d2d

View File

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