public List<BaseWork> getAllWork() {

    List<BaseWork> result = new LinkedList<BaseWork>();
    Set<BaseWork> seen = new HashSet<BaseWork>();

    for (BaseWork leaf: leaves) {
      // make sure all leaves are visited at least once
      visit(leaf, seen, result);
    }

    return result;
  }
getAllWork returns a topologically sorted list of BaseWork
ql/src/java/org/apache/hadoop/hive/ql/plan/TezWork.java