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) ;
	}
public static int [ ] cs_post ( int [ ] parent , int n ) { int j , k = 0 , post [ ] , w [ ] , head [ ] , next [ ] , stack [ ] ; if ( parent == null ) return ( null ) ; post = new int [ n ] ; w = new int [ 3 * n ] ; 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 ; for ( j = n - 1 ; j >= 0 ; j -- ) { if ( parent [ j ] == - 1 ) continue ; next [ next_offset + j ] = head [ parent [ j ] ] ; head [ parent [ j ] ] = j ; } for ( j = 0 ; j < n ; j ++ ) { if ( parent [ j ] != - 1 ) continue ; k = cs_tdfs ( j , k , head , 0 , next , next_offset , post , 0 , stack , stack_offset ) ; } return ( post ) ; }
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