Question: I need help with programming this in C please :) 1.3 balance: Strings and stacks Write a program balance that checks whether a string contains

 I need help with programming this in C please :) 1.3

I need help with programming this in C please :)

1.3 balance: Strings and stacks Write a program balance that checks whether a string contains correctly nested and balanced parentheses, brackets, and braces. Your program will take a single argument and analyze whether each open delimiter has a corresponding closing delimiter of the correct type. If the string is balanced, balance will print nothing and exit with status EXIT_SUCCESS. Other- wise, balance will print an error message and exit with status EXIT_FAILURE. Implementation balance will maintain a stack of open delimiters. Each time a (, [, or { is encountered in the input, it will push that delimiter onto the stack. Each time a ), ), or } is encountered, balance will pop the top delimiter off the stack and check whether it matches the delimiter encountered in the string. If the delimiters do not match, or the stack is empty, balance will print the index for the unexpected delimiter and the closing delimiter encountered. $ ./balance ')' 0: ) $ ./balance '([)]' 2: ) If the stack is not empty when balance reaches the end of the input, it will print the message open followed by a list of closing delimiters in the order needed to balance the string. $ ./balance ([{' open: }]) All non-delimiter characters may be ignored. 3 Notes You are free to use whatever data structures you find convenient. Note that an array can be used to make a stack, if its size is bounded. The optimal algorithm requires O(n) time and uses O(n) space, where n is the length of the input string

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!