In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the method of matching delimiters through stack verification". In daily operation, I believe that many people have doubts about the method of matching delimiters through stack verification. The editor has consulted all kinds of data and sorted out simple and useful operation methods. I hope it will be helpful to answer the doubts of "the method of matching delimiters through stack verification"! Next, please follow the editor to study!
Package helloclean;public class StackX {private int maxSize; private char [] stackArray; private int top; public StackX (int max) {maxSize = max; stackArray = new char [maxSize]; top =-1;} public void push (char j) {stackArray [+ + top] = j;} public char pop () {return stackArray [top--] } public char peek () {return stackArray [top];} public boolean isEmpty () {return (top =-1);}} package helloclean;public class BracketChecker {private String input; public BracketChecker (String in) {this.input = in;} public void check () {int stackSize = input.length (); StackX theStack = new StackX (stackSize); for (int j = 0) J < input.length (); j + +) {char ch = input.charAt (j); switch (ch) {case'{: case'[': case'(': theStack.push (ch); break Case'}': case']': case')': if (! theStack.isEmpty ()) {char chx = theStack.pop () If ((ch = ='}'& & chx! ='{') | (ch = =')'& & chx! ='(') | ch = =']'& & chx! ='[') {System.out.println ("Error:" + ch + "at:" + j) }} else {System.out.println ("Error:" + ch + "at:" + j);} break; default: break }} if (! theStack.isEmpty ()) {System.out.println ("missing right delimiter!");} package helloclean;import java.util.Scanner;public class BracketApp {public static void main (String [] args) {String input; Scanner scanner = new Scanner (System.in) While (true) {System.out.println ("input: eg: (AB [CD] e {fg})"); input = scanner.nextLine (); if (input.equals ("Q")) {System.out.println ("quit!"); break;} BracketChecker bracketChecker = new BracketChecker (input) BracketChecker.check () } input: eg: (AB [CD] e {fg}) abc (de) [fg] {xxxxxmissing right delimiterator input: eg: (AB [CD] e {fg}) abc [ef] ggg) ddError:) at: 10input: eg: (AB [CD] e {fg}) abc (x) dinput: (AB [CD] e {fg}) this ends the study of "matching by stack delimiters" I hope I can solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.