This commit is contained in:
Maryna Kravtsova 2020-10-21 11:29:36 +02:00
parent c8f47a8e0e
commit c88cf9bbbb

View File

@ -3,6 +3,7 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <ctype.h>
struct stack{ struct stack{
char data[100]; char data[100];
@ -67,8 +68,7 @@ char gettop(){
int main(){ int main(){
//struct stack mystack;
//memset(&mystack, 0 , sizeof(struct stack));
char line[100]; char line[100];
s.size = -1; s.size = -1;
@ -78,29 +78,34 @@ int main(){
int l = strlen(line); int l = strlen(line);
int i, j; int i, j;
for(i = 0; i < l; i++){ for(i = 0; i < l; 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]);
} }
else if(line[i] == '}' || line[i] == ')' || line[i] == ']' || line[i] == '>'){ else if(line[i] == '}' || line[i] == ')' || line[i] == ']' || line[i] == '>'){
char a = gettop();
//printf("%c", a);
if(!find_pair(gettop(), line[i])){
char b = right_pair(a);
printf("Crossed bracket %c in %d, expected %c\n", line[i], i, b);
return 0;
} char a = gettop();
else{ if(a != '(' || a != '{' || a != '<' || a != '['){
pop(); printf("Unexpected closing brocket %c in %d\n", line[i], i);
} return 0;
}
else if(s.size == -1 && !find_pair(gettop(), line[i])){
char b = right_pair(a);
printf("Crossed bracket %c in %d, expected %c\n", line[i], i, b);
return 0;
}
else{
pop();
}
} }
}
if(s.size == -1){
printf("All brackest are OK\n");
} }
printf("All brackest are OK\n");
return 0; return 0;
} }