Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type="text/javascript" src="stack.js"></script>
- </head>
- <body>
- <script type="text/javascript">
- var mystack = new Stack();
- var text = prompt("Enter some text", "");
- for (var i = 0; i < text.length; i++) {
- if (text.charAt(i) == '(') {
- mystack.push('(');
- } else if (text.charAt(i) == ')') {
- try {
- mystack.pop();
- } catch (e) {
- alert(e);
- }
- }
- }
- if (mystack.top != -1) {
- alert("Stack not empty after traversing whole text!\n\n" +
- "Brackets don't match.");
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment