Postorders a tree of forest.

@param parent
defines a tree of n nodes
@param n
length of parent
@return post[k]=i, null on error
344640
public static int[] cs_post(int[] parent, int n)
	{
		int j, k = 0, post[], w[], head[], next[], stack[] ;
		if (parent == null) return (null) ;		/* check inputs */
		post = new int [n] ;				/* allocate result */
		w = new int [3*n] ;				/* get workspace */
		if (w == null || post == null) return (cs_idone (post, null, w, false)) ;
		head = w ; next = w ;
		int next_offset = n ;
		stack = w ;
		int stack_offset = 2*n ;
		for (j = 0 ; j < n ; j++) head [j] = -1 ;	/* empty linked lists */
		for (j = n-1 ; j >= 0 ; j--) /* traverse nodes in reverse order*/
		{
			if (parent [j] == -1) continue;		/* j is a root */
			next [next_offset + j] = head [parent [j]] ;  /* add j to list of its parent */
			head [parent [j]] = j ;
		}
		for (j = 0 ; j < n ; j++)
		{
			if (parent [j] != -1) continue ;	/* skip j if it is not a root */
			k = cs_tdfs(j, k, head, 0, next, next_offset, post, 0, stack, stack_offset) ;
		}
		return (post) ;
	}
747212
public function presentParent()
	{
		if ((int)$this->post_parent === 0)
		{
			return null;
		}
		$parent = get_post($this->post_parent);

		return new self($parent, false);
	}
1308229
private Node getParent(Node n) {
        if (n.y_s == null) {
            return null;
        }
        Node c = n.y_s;
        if (c.o_c == n) {
            return c;
        }
        Node p1 = c.y_s;
        if (p1 != null && p1.o_c == n) {
            return p1;
        }
        return c;
    }
426986
public static void sort(BaseComponent parent, boolean recurse) {
        if (parent == null || parent.getChildren().size() < 2) {
            return;
        }

        int i = 1;
        int size = parent.getChildren().size();

        while (i < size) {
            Treenode item1 = (Treenode) parent.getChildren().get(i - 1);
            Treenode item2 = (Treenode) parent.getChildren().get(i);

            if (compare(item1, item2) > 0) {
                parent.swapChildren(i - 1, i);
                i = i == 1 ? 2 : i - 1;
            } else {
                i++;
            }
        }

        if (recurse) {
            for (BaseComponent child : parent.getChildren()) {
                sort(child, recurse);
            }
        }
    }
1313827
public void setParent(AstNode parent) {
        if (parent == this.parent) {
            return;
        }

        // Convert position back to absolute.
        if (this.parent != null) {
            setRelative(-this.parent.getAbsolutePosition());
        }

        this.parent = parent;
        if (parent != null) {
            setRelative(parent.getAbsolutePosition());
        }
    }
940039
def ancestors
      node  = self
      nodes = []
      nodes << node = node.parent while node.parent
      nodes
    end
1267869
def compute_post_order(graph, start_node)
      i = 1
      result = []
      visited = Set.new
      post_order_df = proc do |node|
        visited << node
        node.real_successors.each do |successor|
          post_order_df.call(successor) unless visited.include?(successor)
        end
        result << node
        node.post_order_number = i
        i += 1
      end
      post_order_df.call(start_node)
      result
    end
1199023
public static List<ITree> preOrder(ITree tree) {
        List<ITree> trees = new ArrayList<>();
        preOrder(tree, trees);
        return trees;
    }
575903
public function getParent($n = null)
	{
		return ($n > 1) ? $this->parent->getParent(--$n) : $this->parent;
	}
969832
private function getHierarchy($tree, $place, $parent): ?array
    {
        $child_places = $place->getChildPlaces();
        $numfound     = count($child_places);

        if ($numfound > 0) {
            $divisor = $numfound > 20 ? 3 : 2;

            return
                [
                    'tree'      => $tree,
                    'col_class' => 'w-' . ($divisor === 2 ? '25' : '50'),
                    'columns'   => array_chunk($child_places, (int) ceil($numfound / $divisor)),
                    'place'     => $place,
                    'parent'    => $parent,
                ];
        }

        return null;
    }
961383
@Requires({
    "parent != null",
    "annotation != null"
  })
  @Ensures("result != null")
  @SuppressWarnings("unchecked")
  protected List<Long> getLineNumbers(Element parent,
                                      AnnotationMirror annotation) {
    if (JavaUtils.classExists("com.sun.source.util.Trees")) {
      try {
        return (List<Long>) Class
            .forName("com.google.java.contract.core.apt.JavacUtils")
            .getMethod("getLineNumbers", ProcessingEnvironment.class,
                       Element.class, AnnotationMirror.class)
            .invoke(null, utils.processingEnv, parent, annotation);
      } catch (Exception e) {
        return Collections.emptyList();
      }
    } else {
      return Collections.emptyList();
    }
  }
866757
private static List<JoinNode> generateInnerJoinOrdersForTree(JoinNode subTree) {
        // Get a list of the leaf nodes(tables) to permute them
        List<JoinNode> tableNodes = subTree.generateLeafNodesJoinOrder();
        List<List<JoinNode>> joinOrders = PermutationGenerator.generatePurmutations(tableNodes);
        List<JoinNode> newTrees = new ArrayList<>();
        for (List<JoinNode> joinOrder: joinOrders) {
            newTrees.add(JoinNode.reconstructJoinTreeFromTableNodes(joinOrder, JoinType.INNER));
        }
        //Collect all the join/where conditions to reassign them later
        AbstractExpression combinedWhereExpr = subTree.getAllFilters();
        List<JoinNode> treePermutations = new ArrayList<>();
        for (JoinNode newTree : newTrees) {
            if (combinedWhereExpr != null) {
                newTree.setWhereExpression(combinedWhereExpr.clone());
            }
            // The new tree root node id must match the original one to be able to reconnect the
            // subtrees
            newTree.setId(subTree.getId());
            treePermutations.add(newTree);
        }
        return treePermutations;
    }
615640
private DefaultMutableTreeNode makeNode(Object userObject,
            MutableTreeNode parent) {

        DefaultMutableTreeNode node = new DefaultMutableTreeNode(userObject);

        if (parent != null) {
            treeModel.insertNodeInto(node, parent, parent.getChildCount());
        }

        return node;
    }
614713
protected static void buildTree(EndpointPart parent, String[] parts, int index, String endpointType) {
        // Check if operation qualifier is part of last element
        String name = parts[index];
        String qualifier = null;

        if (index == parts.length - 1) {
            qualifier = EndpointUtil.decodeEndpointOperation(parts[index], false);
            name = EndpointUtil.decodeEndpointURI(parts[index]);
        }

        // Check if part is defined in the parent
        EndpointPart child = parent.addChild(name);

        if (index < parts.length - 1) {
            buildTree(child, parts, index + 1, endpointType);
        } else {
            // Check if part has an operation qualifier
            if (qualifier != null) {
                child = child.addChild(qualifier);
                child.setQualifier(true);
            }
            child.setEndpointType(endpointType);
        }
    }
1083210
private function count_children_from_parent_recursively(array $postparents, int $postid) : int {
        if (!isset($postparents[$postid])) {
            // Post not found at all.
            return 0;
        }

        $count = 0;
        foreach ($postparents as $pid => $parentid) {
            if ($postid == $parentid) {
                $count += $this->count_children_from_parent_recursively($postparents, $pid) + 1;
            }
        }

        return $count;
    }
553955
private void parseSubHierarchy(final Node parent, final AvroNode n) {
    final Node parsed;
    if (n.getPackageNode() != null) {
      parsed = new PackageNodeImpl(parent, getString(n.getName()), getString(n.getFullName()));
    } else if (n.getNamedParameterNode() != null) {
      final AvroNamedParameterNode np = n.getNamedParameterNode();


      parsed = new NamedParameterNodeImpl<>(parent, getString(n.getName()), getString(n.getFullName()),
              getString(np.getFullArgClassName()), getString(np.getSimpleArgClassName()), np.getIsSet(), np.getIsList(),
              getString(np.getDocumentation()), getString(np.getShortName()), getStringArray(np.getInstanceDefault()));
    } else if (n.getClassNode() != null) {
      final AvroClassNode cn = n.getClassNode();
      final List<ConstructorDef<?>> injectableConstructors = new ArrayList<>();
      final List<ConstructorDef<?>> allConstructors = new ArrayList<>();

      for (final AvroConstructorDef injectable : cn.getInjectableConstructors()) {
        final ConstructorDef<?> def = parseConstructorDef(injectable, true);
        injectableConstructors.add(def);
        allConstructors.add(def);
      }
      for (final AvroConstructorDef other : cn.getOtherConstructors()) {
        final ConstructorDef<?> def = parseConstructorDef(other, false);
        allConstructors.add(def);
      }
      @SuppressWarnings("unchecked")
      final ConstructorDef<Object>[] dummy = new ConstructorDef[0];
      parsed = new ClassNodeImpl<>(parent, getString(n.getName()), getString(n.getFullName()), cn.getIsUnit(),
              cn.getIsInjectionCandidate(), cn.getIsExternalConstructor(), injectableConstructors.toArray(dummy),
              allConstructors.toArray(dummy), getString(cn.getDefaultImplementation()));
    } else {
      throw new IllegalStateException("Bad avro node: got abstract node" + n);
    }

    for (final AvroNode child : n.getChildren()) {
      parseSubHierarchy(parsed, child);
    }
  }
1076102
@Pure
	public final OctTreeZone zoneOf(N child) {
		final int idx = indexOf(child);
		final OctTreeZone[] zones = OctTreeZone.values();
		if (idx < 0 || idx >= zones.length) {
			return zones[idx];
		}
		return null;
	}