package project_2;

public class CheckValid {

/*
 * This Class Check if the brackets is true
 * */

	public  static boolean checkEquation(String equation){
		if(equation==null)
			return false;
		
		Stack<Character> stack = new Stack<>();
		char top;
		
		for (int i = 0; i < equation.length(); i++) {
			
			if(equation.charAt(i)=='(' || equation.charAt(i)=='[' || equation.charAt(i)=='{'){
				stack.push(equation.charAt(i));
			}
			
			if(equation.charAt(i)==')'){
				if(stack.isEmpty())
					return false;
				top=stack.top();
				if(top=='(')
					stack.pop();
				else
					return false;
			}
			
			if(equation.charAt(i)==']'){
				if(stack.isEmpty())
					return false;
				top=stack.top();
				if(top=='[')
					stack.pop();
				else
					return false;

			}
			
			if(equation.charAt(i)=='}'){
				if(stack.isEmpty())
					return false;
				
				top=stack.top();
				if(top=='{')
					stack.pop();
				else
					return false;

			}
			

		}
		if(stack.isEmpty())
			return true;
		else
			return false;
	}

	
}
