xml地图|网站地图|网站标签 [设为首页] [加入收藏]

您的位置:www.2977.com > 澳门新葡萄京官网注册 > 澳门新葡萄京官网注册中缀表明式转为后缀表明

澳门新葡萄京官网注册中缀表明式转为后缀表明

发布时间:2019-07-20 07:52编辑:澳门新葡萄京官网注册浏览(66)

    内部的恋爱纯纯的!笔者正是爱抚这些味.无需太过多的杂质.....睇左之后,另本身回想左<失恋33天>里面的一句,"借使全体爱情都像你所讲同样才是例行,那么笔者令愿晚景凄凉"

    1、 UIScrollView中间嵌套三个tableView,侧边一个tableView 又要兑现左滑删除功效,写好左滑删除的代办方法,打算调节和测量检验... 发掘tableView左滑失效了,调节和测量检验发掘原本是UIScrollView的滑行手势和tableView的左滑手势争辩了。

    率先我们想设计的表明式补助的数:整数(正整数,0,负整数)还应该有小数,注意了非但只帮忙个位整数(此前做的都太局限了)

    怎么里面包车型大巴女一号甘似"持田香织"

    2、写了二个再而三UISrollViewMyScrollView,在里边重写

    那么大家健康的表明式要做一下管理,让它能分别出操作符和操作数,方便大家越来越好的拍卖

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    {
      NSLog(@"_____%@______other:%@",gestureRecognizer,otherGestureRecognizer);
    return NO;
    }
    

    想尽:假使有东西能够隔开操作符和操作数就好了.。那行,那大家就用空格隔绝呢

    (上面方法是UIGestureRecognizerDelegate有两个没公开的函数之一,只要重载了就会被调用,是可以通过appstore审核的)
    调治输出发掘 return NO会忽略otherGestureRecognizer 手势(被拦截) ;return YES则会调用 otherGestureRecognizer的办法(不阻碍);不过急需是cell左滑的手势能够执行,并不是具有的手势;单纯的return YES会造成UISrollView 不大概左右滑行。

    为啥要用空格?

    3、知道地点的的主题材料,那大家只要求剖断若是otherGestureRecognizercell左滑的手势 return yes 即可,其他return no。 通过调节和测量试验打字与印刷发掘

    因为有时候大家输入平常的表明式的时候会习于旧贯性的按下空格,使用空格作为分隔,以往大家会将空格管理掉,也就无形中的拍卖掉了习贯性而发出的难题。

    ___<UIScrollViewPanGestureRecognizer: 0x138081870; state = Possible; delaysTouchesEnded = NO; view = <ANTScrollView 0x1370e9400>; target= <(action=handlePan:, target=<ANTScrollView 0x1370e9400>)>; must-fail = {
            <UIScrollViewPagingSwipeGestureRecognizer: 0x138014430; state = Failed; view = <ANTScrollView 0x1370e9400>; target= <(action=_handleSwipe:, target=<ANTScrollView 0x1370e9400>)>>
        }>______other:<UIScrollViewPanGestureRecognizer: 0x1380175c0; state = Possible; cancelsTouchesInView = NO; delaysTouchesEnded = NO; view = <UITableViewWrapperView 0x1370cec00>; targets= <(
        "(action=handlePan:, target=<UITableViewWrapperView 0x1370cec00>)",
        "(action=handleSwipeBeginning:, target=<UITableViewWrapperView 0x1370cec00>)"
    )>>
    2016-07-14 14:53:32.463 antQueen[7614:3034218] ___<UIScrollViewPanGestureRecognizer: 0x138081870; state = Possible; delaysTouchesEnded = NO; view = <ANTScrollView 0x1370e9400>; target= <(action=handlePan:, target=<ANTScrollView 0x1370e9400>)>; must-fail = {
            <UIScrollViewPagingSwipeGestureRecognizer: 0x138014430; state = Failed; view = <ANTScrollView 0x1370e9400>; target= <(action=_handleSwipe:, target=<ANTScrollView 0x1370e9400>)>>
        }>______other:<UIScrollViewDelayedTouchesBeganGestureRecognizer: 0x13807a5a0; state = Possible; delaysTouchesBegan = YES; view = <UITableView 0x13703f000>; target= <(action=delayed:, target=<UITableView 0x13703f000>)>>
    2016-07-14 14:53:32.472 antQueen[7614:3034218] ___<UIScrollViewPanGestureRecognizer: 0x138081870; state = Possible; delaysTouchesEnded = NO; view = <ANTScrollView 0x1370e9400>; target= <(action=handlePan:, target=<ANTScrollView 0x1370e9400>)>; must-fail = {
            <UIScrollViewPagingSwipeGestureRecognizer: 0x138014430; state = Failed; view = <ANTScrollView 0x1370e9400>; target= <(action=_handleSwipe:, target=<ANTScrollView 0x1370e9400>)>>
        }>______other:<UIScrollViewDelayedTouchesBeganGestureRecognizer: 0x136db8360; state = Possible; delaysTouchesBegan = YES; view = <ANTScrollView 0x1370e9400>; target= <(action=delayed:, target=<ANTScrollView 0x1370e9400>)>>
    

    那好大家一贯上代码,里面有详细的注释

    作者们开掘其间有个UITableViewWrapperView那几个就是大家要找的view,然后我们在格局里面做个判定:

    /**
         * 40开括号( 41闭括号) 42星号(乘号) 43加号 45减号 46句号(小数点) 47斜杠(除号) 48 数字0 57 数字9
         */
        public static void main(String[] args) {
            String str = "(2 3.2) Math.ceil(4)*(409-56 (-136/5)*9)";
            StringBuilder sb = new StringBuilder();
            char lastC = 0;
            char c = 0;
            for (int i = 0; i < str.length(); i  ) {
                c = str.charAt(i);
                if (c > 57 || c < 48) {// 非数字
                    if (c == 46 && lastC <= 57 && lastC >= 48) {// 小数点       如果c为小数点,并且lastC为数字,那就直接append到sb里面
                        sb.append(c);
                    } else if (lastC == 40 && c == 45) {// 负数   如果lastC为左括号,c为减号或者负号(减号),那就直接append到sb里面
                        sb.append(c);
                    } else if (c == 40 || c == 41 || c == 42 || c == 43 || c == 45
                            || c == 47) {//如果是左括号 右括号 乘号 加号 减号 除号 则空格隔开,在append到sb里面
                        sb.append(" ").append(c).append(" ");
                    }else{//其他字符直接append到sb里面
                        sb.append(c);
                    }
                } else {// 数字 是数字就直接append到sb里面
                    sb.append(c);
                }//记录上一个字符
                lastC = c;
            }
            System.out.println(sb.toString());
        }
    
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    {
        if ([otherGestureRecognizer.view isKindOfClass:NSClassFromString(@"UITableViewWrapperView")]) {
            return YES;
        }
        NSLog(@"_____%@______other:%@",gestureRecognizer,otherGestureRecognizer);
        return NO;
    }
    

    运营结果:

    马到功成...调节和测量试验发掘cell能够兑现左滑。

    澳门新葡萄京官网注册 1

    经过地方的个人方法,也足以去化解UIScrollView滑动与UINavigationVIewController的手势重回的争执(自个儿研讨下啊!)

    本条表达式(2 3.2) Math.ceil(4)*(409-56 (-136/5)*9)大约涵括了独具的可能,大家先忽略Math.ceil那一个字符串,那是在下一篇用到了,为了是我们的表明式越来越丰富。

    这好,大家回归正题,怎么着将常规的表明式写出逆波兰共和国表明式呢?

    思路:

      ①我们用三个一直以来体积的数组strs来积攒关于逆波兰共和国(The Republic of Poland)表达式的字符串,最终将会造成逆波兰共和国表明式,用贰个栈stack s来保存操作符

      ②从左到右遍历字符串数组

      ③当遇到操作数时,间接存款和储蓄到数组strs里面

      ④当遭逢操作符是,就要相比较其与栈顶的刚开始阶段级

        1、当栈stack为空,或栈顶运算符为左括号“(”,则一向将此操作符入栈;

        2、不然,若优先级比栈顶运算符的高,也将操作符压入S1

        3、不然,将stack栈顶的演算符弹出并蕴藏到strs数组中,再一次转到(③-1)与stack中新的栈顶运算符绝相比;

     

      ⑤遇见括号:

        1、当碰到左括号"{"时,将它压入栈里面

        2、当遭受右括号")"时,依次弹出操作符并且增进到sb里面,直到碰到左括号“(”,此时左右括号都作废

      ⑥重复②~⑤的步骤

      ⑦当遍历结束后,将栈里面剩余的操作符依次弹出何况拉长到数组strs里面

    例如

    (2 3.2) 4*(40-5 (-1)*4)    -------->  2 3.2 4 40 5 - -1 4 * *

     ( 2 3.2 )   4 *  ( 40 - 5  ( -1 )  * 4 )      ---------调换为数组--------->     [(, 2, , 3.2, ), , 4, *, (, 40, -, 5, , (, -1, ), *, 4, )]

    遍历到的字符串:str

    积攒关于逆波兰共和国字符串的数组:strs

    存款和储蓄操作符的stack

              str                                 strs                              stack        理由

         (             空            (      左括号,压入栈中

         2               ["2"]           (      数字,直接存款和储蓄到数组strs里面 

                         ["2"]            (        操作符压入栈中

         3.2            ["2","3.2"]         (        数字,间接存款和储蓄到数组strs里面

           )           ["2,"3.2"," "]         空      右括号,将操作符依次弹出,直到左括号,那时左括号已经弹出,stack空

                         ["2,"3.2"," "]                stack为空,直接压入栈

        4                 ["2,"3.2"," ","4"]                               操作数,直接存款和储蓄到strs里面

        *                 ["2,"3.2"," ","4"]         *      操作符*号比栈顶的 号高,将*压入栈

           (                 ["2,"3.2"," ","4"]         * (       左括号一向压入栈顶

        40        ["2,"3.2"," ","4","40"]        * (     数字,直接存款和储蓄到数组strs里面

        -        ["2,"3.2"," ","4","40"]        * ( -      栈顶为左括号,操作符直接压入栈

          5        ["2,"3.2"," ","4","40","5"]        * ( -     数字,直接存储到数组strs里面

                   ["2,"3.2"," ","4","40","5","-"]       * (     操作符 号并从未比操作符-号优先,所以将-号弹出,在跟新的栈顶相比较

       (            ["2,"3.2"," ","4","40","5","-"]        * ( (    左括号直接压入栈顶

       -1        ["2,"3.2"," ","4","40","5","-","-1"]      * ( (    数字,直接存款和储蓄到数组strs里面

       )       ["2,"3.2"," ","4","40","5","-","-1"]     * (      遭逢了右括号,依次弹出,直到遭逢左括号

          *       ["2,"3.2"," ","4","40","5","-","-1"]     * ( *    操作符*号的预先级比操作符 号高,直接压入栈

          4     ["2,"3.2"," ","4","40","5","-","-1","4"]      * ( *    数字,直接存款和储蓄到数组strs里面

       )     ["2,"3.2"," ","4","40","5","-","-1","4","*"," "]       *       右括号,依次弹出,直到遭受左括号

      最后   ["2,"3.2"," ","4","40","5","-","-1","4","*"," ","*"," "]  空     依次弹出栈里面包车型客车操作符,直到为空

    那么我们最终获得的数组["2,"3.2"," ","4","40","5","-","-1","4","*"," ","*"," "] 是还是不是跟我们要的逆波兰共和国(The Republic of Poland)表达式2 3.2 4 40 5 - -1 4 * * 完全同样

    那么接下去,上代码

    // (2 3.2) 4*(40-5 (-1)*4)
        static String strs[] = { "(", "2", " ", "3.2", ")", " ", "4", "*", "(",
                "40", "-", "5", " ", "(", "-1", ")", "*", "4", ")" };// 正常的表达式经过上面的处理,变成了这样的数组
        static String strsBo[] = new String[strs.length];// 存储关于逆波兰的字符串数组
        static int index = 0;// strsBo的下一个存储下标,从0开始
        static Stack<String> stack = new Stack<>();// 存储操作符的栈
    
        public static void main(String[] args) {
            for (String str : strs) {
                if (str.matches("-?[0-9] ") || str.matches("-?[0-9] .?[0-9] ")) {// 判断是否是数值
                    strsBo[index  ] = str;
                } else {
                    handleStack(str);
                }
            }
            // 当遍历结束后,将栈里面剩余的操作符依次弹出并且添加到数组strs里面
            while (stack != null && !stack.empty()) {
                strsBo[index  ] = stack.pop();
            }
            System.out.println(Arrays.toString(strsBo));
        }
    
        private static void handleStack(String str) {
            if (str.equals("(")) {// 当遇到左括号"("时,将它压入栈里面
                stack.push(str);
            } else if (str.equals(")")) {// 遇到了右括号,依次弹出操作符并且添加到strsBo里面,直到遇到左括号“(”,此时左右括号都作废
                String pop = stack.pop();
                while (!pop.equals("(")) {
                    strsBo[index  ] = pop;
                    pop = stack.pop();
                }
            } else if (stack.isEmpty() || stack.lastElement().equals("(")) {// 栈stack为空,或栈顶运算符为左括号“(”,则直接将此操作符入栈
                stack.push(str);
            } else {// 操作符不为右括号,才比较优先级
                if (priority(str, stack.lastElement())) {// 若优先级比栈顶运算符的高,也将操作符压入stack
                    stack.push(str);
                } else {// 否则,将stack栈顶的运算符弹出并存储到strs数组中,再次与stack中新的栈顶运算符相比较
                    strsBo[index  ] = stack.pop();
                    handleStack(str);
                }
            }
        }
    
        /**
         * @return 只有str1的优先级高于str2的优先级才返回false
         *         ,只有一种情况才返回true,那就是str1为乘除,str2为加减,其他情况都为false
         */
        public static boolean priority(String str1, String str2) {
            return (str1.equals("*") || str1.equals("/"))
                    && (str2.equals(" ") || str2.equals("/"));
        }
    

    运营结果:

    澳门新葡萄京官网注册 2

    没难点,跟大家要的结果一律。下一篇将会用面向对象的思辨来将他们包裹一下,是他们更便于的扩充。

    本文由www.2977.com发布于澳门新葡萄京官网注册,转载请注明出处:澳门新葡萄京官网注册中缀表明式转为后缀表明

    关键词: www.2977.com

上一篇:十三个原因,第一季总结

下一篇:没有了