Write an Algorithm for Balanced Parentheses for the followin

Write an Algorithm for Balanced Parentheses for the following code. Don\'t use a stack, and show what are the the results? {int x = 5; double [] csci235; double[scores = 5.7, 4.8, 12.89, 3.21, 52.34}; {{for(int i = 0; 1

Solution

Step 1: Store the Expression in a character array

Step 2: Create an Enumeration for each parenthesis (open and close).

Step 3: Create an array OPEN whose size is equal to number of open parenthesis taken in the enumeration.

Step 4: Create an array CLOSE whose size is equal to number of close parenthesis taken in the enumeration.

Step 5: Repeat Step 6 and Step 7 till Expression character is empty

Step 6: Extract a character from the Expression array

Step 7: If the extracted character is an open parenthesis

                Then Increment the OPEN index position (index position: is the enumeration number for the open parenthesis) by one.

If the extracted character is a close parenthesis

                Then Increment the CLOSE index position (index position: is the enumeration number for the close parenthesis) by one.

Step 8: Compare the each index position of OPEN and CLOSE (Non Zero value index position)

If it is not equal then mismatch of parenthesis

If it is equal then parenthesis are matching.

 Write an Algorithm for Balanced Parentheses for the following code. Don\'t use a stack, and show what are the the results? {int x = 5; double [] csci235; doubl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site