/* * Author: Walter * Student ID: 1930006025 * Assignment_1_problem_2 * validbrackets function */ #include #include #include "stack.h" #include "validbrackets.h" /* all the left brackets */ static char LEFTBRACKETS[] = "({[<"; /* all the right brackets */ static char RIGHTBRACKETS[] = ")}]>"; /* number of brackets pairs */ static int BRACKETS_LEN = 4; bool ValidBrackets(char *str) { /* if string pass all the test, will return default value 'true' */ bool result = true; /* null pointer will return false */ if (str == NULL) { return false; } /* tmp value to store the left brackets */ char left; /* length of string */ size_t str_len = strlen(str); Stack stack; /* only half length of the string is enougth, * empty stack is allowed */ CreateStack(&stack, str_len/2); /* loop for all char in string */ for (size_t i=0; i