Beispiel #1
0
/*
 * Post order a tree
 */
int *TreePostorder(
	int n,
	int *parent
)
{
	int	v, dad;

	/* Allocate storage for working arrays and results	*/
	first_kid = 	mxCallocInt (n+1);
	next_kid  = 	mxCallocInt (n+1);
	post	  = 	mxCallocInt (n+1);

	/* Set up structure describing children */
	for (v = 0; v <= n; first_kid[v++] = -1);
	for (v = n-1; v >= 0; v--) {
		dad = parent[v];
		next_kid[v] = first_kid[dad];
		first_kid[dad] = v;
	}

	/* Depth-first search from dummy root vertex #n */
	postnum = 0;
	etdfs (n);

	SUPERLU_FREE (first_kid);
	SUPERLU_FREE (next_kid);
	return post;
}
Beispiel #2
0
static
/*
 * Depth-first search from vertex v.
 */
void etdfs (
	int	v
	)
{
	int	w;

	for (w = first_kid[v]; w != -1; w = next_kid[w]) {
		etdfs (w);
	}
	/* post[postnum++] = v; in Matlab */
	post[v] = postnum++;    /* Modified by X.Li on 2/14/95 */
}
static
/*
 * Depth-first search from vertex v.
 */
void etdfs (
	    int_t	  v,
	    int_t   first_kid[],
	    int_t   next_kid[],
	    int_t   post[], 
	    int_t   *postnum
	    )
{
	int	w;

	for (w = first_kid[v]; w != -1; w = next_kid[w]) {
		etdfs (w, first_kid, next_kid, post, postnum);
	}
	/* post[postnum++] = v; in Matlab */
	post[v] = (*postnum)++;    /* Modified by X. Li on 08/10/07 */
}
/*
 * Post order a tree
 */
int_t *TreePostorder_dist(
			  int_t n,
			  int_t *parent
			  )
{
	int_t	v, dad;
	int_t   *first_kid, *next_kid, *post, postnum;

	/* Allocate storage for working arrays and results	*/
	if ( !(first_kid = mxCallocInt (n+1)) )
	    ABORT("mxCallocInt fails for first_kid[]");
	if ( !(next_kid = mxCallocInt (n+1)) )
	    ABORT("mxCallocInt fails for next_kid[]");
	if ( !(post = mxCallocInt (n+1)) )
	    ABORT("mxCallocInt fails for post[]");

	/* Set up structure describing children */
	for (v = 0; v <= n; first_kid[v++] = -1);
	for (v = n-1; v >= 0; v--) {
		dad = parent[v];
		next_kid[v] = first_kid[dad];
		first_kid[dad] = v;
	}

	/* Depth-first search from dummy root vertex #n */
	postnum = 0;
#if 0
	/* recursion */
	etdfs (n, first_kid, next_kid, post, &postnum);
#else
	/* no recursion */
	nr_etdfs(n, parent, first_kid, next_kid, post, postnum);
#endif

	SUPERLU_FREE(first_kid);
	SUPERLU_FREE(next_kid);
	return post;
}