Guest User

Untitled

a guest
Jun 14th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="stack.js"></script>
  4. </head>
  5. <body>
  6. <script type="text/javascript">
  7. var mystack = new Stack();
  8. var text = prompt("Enter some text", "");
  9. for (var i = 0; i < text.length; i++) {
  10. if (text.charAt(i) == '(') {
  11. mystack.push('(');
  12. } else if (text.charAt(i) == ')') {
  13. try {
  14. mystack.pop();
  15. } catch (e) {
  16. alert(e);
  17. }
  18. }
  19. }
  20. if (mystack.top != -1) {
  21. alert("Stack not empty after traversing whole text!\n\n" +
  22. "Brackets don't match.");
  23. }
  24. </script>
  25. </body>
  26. </html>
Add Comment
Please, Sign In to add comment