This project implements stack-based solutions for two problems:
- Balanced Parenthesis Check: Verifies if parentheses in a given string are balanced using stack operations.
- String Inversion: Reverses a given string using a stack.
Both implementations utilize a custom stack class built with sequential allocation in Java.
- Checks if strings containing parentheses (
(),{},[]) are balanced. - Returns
trueif balanced, otherwisefalse. - Example:
- Input:
{[()]} - Output: Balanced
- Input:
- Reverses a string of any length (up to 80 characters) using a stack.
- Supports all types of characters, including alphabets, numbers, and special characters.
- Example:
- Input:
Hello, World! - Output:
!dlroW ,olleH
- Input:
The Stack class provides basic stack operations:
- Create: Initializes an empty stack.
- Push: Adds an element to the stack.
- Pop: Removes and returns the top element of the stack.
- Peek: Returns the top element without removing it.
- IsEmpty: Checks if the stack is empty.
- IsFull: Checks if the stack is full.
Stack.java: Contains theStackclass implementation.BalancedParenthesisChecker.java: Implements the balanced parenthesis check functionality.StringInversion.java: Implements the string inversion functionality.
- Clone the repository:
git clone <repository_url>
- Navigate to the project directory and compile the Java files:
javac Stack.java BalancedParenthesisChecker.java StringInversion.java
- Run the desired functionality:
- For balanced parenthesis check:
java BalancedParenthesisChecker
- For string inversion:
java StringInversion
- For balanced parenthesis check:
Input: {[()]} {[(])} ([{}])
Expression: {[()]} -> Balanced
Expression: {[(])} -> Not Balanced
Expression: ([{}]) -> Balanced
Input: "Hello, World!"
Original: Hello, World! -> Reversed: !dlroW ,olleH
Feel free to fork this repository and submit pull requests for any improvements or additional features.