private Result recursiveFind(ListNode tail, ListNode head) { if (tail == null) { return new Result(head, true); } Result result = recursiveFind(tail.next, head); if (result.isTerminated) { return result; } else { if (tail == result.modifiedHead || tail.next == result.modifiedHead) { result.isTerminated = true; return result; } if (result.result) { if (tail.val != result.modifiedHead.val) { result.modifiedHead = null; result.result = false; result.isTerminated = true; return result; } else { result.modifiedHead = result.modifiedHead.next; result.result = true; result.isTerminated = false; return result; } } } return result; }
public Result exe(String src) { Result res = new Result(); long start = System.currentTimeMillis(); try { List lists = Parser.parse(src); res.result = new Begin().invoke(global(), lists).toString(); } catch (ParseException pe) { res.result = "Syntax Error -> " + pe.getMessage(); } catch (EvalException ee) { res.result = "Runtime Error -> " + ee.getMessage(); } catch (RuntimeException re) { res.result = "Fatal Error -> " + re.getMessage(); re.printStackTrace(); } res.callcnt = sand.get().getCallNum(); res.calltime = System.currentTimeMillis() - start; writer().flush(); return res; }
public static Result isPalindromRecurse(SNode n, int len) { assert (len == 2) : "Length reaches" + len; if (n == null || len == 0) { return new Result(null, true); } else if (len == 1) { return new Result(n.next, true); } else if (len == 2) { return new Result(n.next.next, n.key == n.next.key); } Result res = isPalindromRecurse(n.next, len - 2); if (!res.result || res.node == null) { return res; } else { res.result = n.key == res.node.key; res.node = res.node.next; return res; } }