0% found this document useful (0 votes)
16 views

Lab 04 - Stack Vs Queue

This document provides instructions for Lab 4 on stacks and queues. Students are asked to complete 3 problems: 1) implement a function to check the validity of parentheses in a string using stacks, 2) implement a function to evaluate a postfix expression using stacks, and 3) implement a function to evaluate a prefix expression using stacks. Example inputs and outputs are provided for each problem. Students are expected to complete the problems before the lab and submit their code by the end of the lab session.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Lab 04 - Stack Vs Queue

This document provides instructions for Lab 4 on stacks and queues. Students are asked to complete 3 problems: 1) implement a function to check the validity of parentheses in a string using stacks, 2) implement a function to evaluate a postfix expression using stacks, and 3) implement a function to evaluate a prefix expression using stacks. Example inputs and outputs are provided for each problem. Students are expected to complete the problems before the lab and submit their code by the end of the lab session.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

HCMUT/CO2003 Spring 2019

Lab 4 – Stack vs Queue


-----------
Instructions:
- You are expected to completed Problems 1 - 3 before attending the lab.
- Please submit the hardcopy of your program by the end of the lab.

1. Your tasks
The initial code for this lab provide you a skeleton to implement the following functions. Your tasks
are to complete these functions to make them work.

Problem 1.
Complete bool checkParentheses(char* arr) function that check a sequences of parentheses is
valid or not. Parentheses include regular parentheses (), square brackets [], and braces {}.

Example
char s1[] = "{(())}[]";
cout << checkParentheses(s1) << endl; // Output: 1 (Valid)
char s2[] = "({)}[]";
cout << checkParentheses(s2) << endl; // Output: 0 (Invalid)

Problem 2.
Complete int evaluatePostfixExpression(char* exp) function that return the result of the
postfix expression in exp. Note that the input expression only contains addition, subtraction,
multiplication, division on single digit numbers (operands).
Example:

char s3[] = "35+7*"; // equivalent to (3 + 5) * 7


cout << evaluatePostfixExpression(s3) << endl; // Output: 56

Problem 3.
Complete int evaluatePrefixExpression(char* exp) function that return the result of the
prefix expression in exp. Note that the input expression only contains addition, subtraction,
multiplication, division on single digit numbers (operands).
Example:

char s4[] = "-+98*72"; // equivalent to (9 + 8) - 7*2


cout << evaluatePrefixExpression(s4) << endl; // Output: 3

Instructor: Rang Nguyen TA: Thinh Vuong, Duy Tran

You might also like