You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
798 B

  1. using System.Collections.Generic;
  2. namespace JobNimbus_application
  3. {
  4. public static class BracketService
  5. {
  6. public static bool isFullyBracketed(string value){
  7. Stack<int> bracketStack = new Stack<int>();
  8. foreach(char c in value){
  9. switch(c){
  10. case '{':
  11. bracketStack.Push(1);
  12. break;
  13. case '}':
  14. if(bracketStack.Count == 0){ //If the stack is empty there is a closed bracket without an opening bracket
  15. return false;
  16. }
  17. bracketStack.Pop();
  18. break;
  19. }
  20. }
  21. return bracketStack.Count == 0;
  22. }
  23. }
  24. }