A string may use more than one type of delimiter to bracket information into blocks. For example, a string may use braces { }, parentheses ( ), and brackets [ ] as delimiters. A string is properly delimited if each right delimiter is matched with a preceding left delimiter of the same type in such a way that either the resulting blocks of information are disjoint, or one of them is completely nested within the other. Write a program that uses a single stack to check whether a string containing braces, parentheses, and brackets is properly delimited. Use input file string.txt as input to test your program. Each line in the input file is a string. If the string is properly delimited, display a message stating so. If it is not properly delimited, display a message stating so. For example, if the input file contains the following 3 lines of strings: if (a[i] > b[i]) while (c[index] < 0) { a++; b--; c[index++];} for ({int i = 0; num[i }]; would display the following output: Processing input file... String: 1. is properly delimited 2. is properly delimited 3. is not properly delimited End of file.
A string may use more than one type of delimiter to bracket information into blocks. For example, a string may use braces { }, parentheses ( ), and brackets [ ] as delimiters.
A string is properly delimited if each right delimiter is matched with a preceding left delimiter of the same type in such a way that either the resulting blocks of information are disjoint, or one of them is completely nested within the other.
Write a program that uses a single stack to check whether a string containing braces, parentheses, and brackets is properly delimited.
Use input file string.txt as input to test your program.
Each line in the input file is a string. If the string is properly delimited, display a message stating so. If it is not properly delimited, display a message stating so.
For example, if the input file contains the following 3 lines of strings:
if (a[i] > b[i])
while (c[index] < 0) { a++; b--; c[index++];}
for ({int i = 0; num[i }];
would display the following output:
Processing input file... String: 1. is properly delimited 2. is properly delimited 3. is not properly delimited End of file. |
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images