CS301P-Assignment 2 Solution Fall 2024 by M.junaid Qazi
CS301P-Assignment 2 Solution Fall 2024 by M.junaid Qazi
Please carefully read the following instructions before attempting the assignment Solution.
NOTE
Don't copy-paste the same answer.
Make sure you can make some changes to your solution file before submitting copy
paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an Assignment GDB checks your assignment requirement file.
Code:
#include <iostream>
using namespace std;
CONTACT ON WHATSAPP
+923074960034
// Stack class for stack operations
class Stack {
private:
Node* top;
public:
Stack() : top(NULL) {}
~Stack() {
while (!isEmpty()) {
pop();
}
}
void pop() {
if (isEmpty()) {
cout << "Stack is empty, cannot pop." << endl;
return;
}
Node* temp = top;
top = top->next;
delete temp;
CONTACT ON WHATSAPP
+923074960034
}
char peek() {
if (isEmpty()) {
cout << "Stack is empty." << endl;
return '\0'; // Return a null character if stack is empty
}
return top->data;
}
bool isEmpty() {
return top == NULL;
}
};
CONTACT ON WHATSAPP
+923074960034
if (ch == '(' || ch == '{' || ch == '[') {
stack.push(ch);
} else {
// If stack is empty and a closing bracket is found
if (stack.isEmpty()) {
cout << "Brackets are not balanced." << endl;
return false;
}
CONTACT ON WHATSAPP
+923074960034
}
}
int main() {
string input;
cout << "=========================" << endl;
cout << "My VUID is BC12345678" << endl;
cout << "=================================" << endl;
cout << "Enter a string of brackets: ";
cin >> input;
isBalanced(input);
return 0;
}
OUTPUT:
CONTACT ON WHATSAPP
+923074960034
Every Assignment/GDB is change due to unique Student ID so don’t copy
That is truly perfect step by step idea solution get help easily.
CONTACT ON WHATSAPP
+923074960034