offsetforest.java

来自「和YACC一样」· Java 代码 · 共 82 行

JAVA
82
字号
/*File:	 OffsetForest.javaAuthor:  zerksis d. umrigar (zdu@acm.org)Copyright (C) 1997 Zerksis D. UmrigarLast Update Time-stamp: "97/07/19 19:59:11 zdu"This code is distributed under the terms of the GNU General Public License.See the file COPYING with this distribution, or		http://www.fsf.org/copyleft/gpl.htmlTHERE IS ABSOLUTELY NO WARRANTY FOR THIS PROGRAM.*/package zdu.zydebug;import zdu.zydebug.OffsetTree;/* Implement an OffsetForest as nothing but an OffsetTree with a hidden * invisible root.   * * IMPORTANT NOTE: If the OffsetTree's in the forest are shared in other * data-structures, it is safe to change their tree structure only * AFTER they have been removed from the forest. */class OffsetForest {  OffsetForest() {    root= new OffsetTree("");  }  int size() {    return root.nKids();  }  void push(OffsetTree t) {    root.addKid(t);  }  void addElement(OffsetTree t) {    root.addKid(t);  }  OffsetTree pop() {        return (OffsetTree) root.rmKid(root.nKids() - 1);  }  OffsetTree elementAt(int i) {    return (OffsetTree) root.kid(i);  }  OffsetTree peek() {    return (OffsetTree) root.kid(root.nKids() - 1);  }  int leftWidth() {    return root.leftWidth();  }  int rightWidth() {    return root.rightWidth();  }  int height() {    return root.height() - 1;  }  //this implementation requires the gc to collect one more node, but is  //trivial compared to removing all kids.  void removeAllElements() {    root= new OffsetTree("");  }  private OffsetTree root;    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?