DSA Micro Project Report Format
DSA Micro Project Report Format
Group Member
Sr. No. Enrollment Number Name
1 236020307150 PARMAR MANTHANRAJSINH NIKUNJ
2 236020307147 PARMAR DHAVAL HASMUKHBHAI
3 236020307117 MARADIYA DHYEY ALPESHKUMAR
4 236020307138 PANDYA LAKSHANK NAIMISHKUMAR
This code implements a stack-based approach to check if parentheses in an expression are
balanced. It defines a `Stack` class with methods to push and pop elements, and a
`Parenthesis_check` function that uses this stack to verify if each opening parenthesis `(`
has a corresponding closing parenthesis `)`. The program takes an expression as input and
determines whether the parentheses are balanced or not.
Code:
#include <iostream>
#include <string>
using namespace std;
class Stack
{
private:
char *arr;
int size;
int top;
public:
Stack(int size);
Stack::Stack(int size)
{
this->size = size;
top = -1;
arr = new char[size];
}
int Stack::pop()
{
if (top >= 0)
{
top--;
return 1;
}
else
{
return 0;
}
}
void Stack::print_stack()
{
for (int i = top; i != -1; i--)
{
cout << arr[i] << " ";
}
cout << endl;
}
if (s.top == -1)
{
cout << "Parenthesis is balanced" << endl;
return 1;
}
else
{
cout << "Parenthesis is not balanced" << endl;
return 0;
}
}
int main()
{
string str;
cout << "Enter a expression : ";
cin >> str;
Parenthesis_check(str);
return 0;
}
Output:
Parenthesis is balanced