EVSL  1.1.0
EigenValues Slicing Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
cs_tdfs.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* depth-first search and postorder of a tree rooted at node j */
3 CS_INT cs_tdfs (CS_INT j, CS_INT k, CS_INT *head, const CS_INT *next, CS_INT *post, CS_INT *stack)
4 {
5  CS_INT i, p, top = 0 ;
6  if (!head || !next || !post || !stack) return (-1) ; /* check inputs */
7  stack [0] = j ; /* place j on the stack */
8  while (top >= 0) /* while (stack is not empty) */
9  {
10  p = stack [top] ; /* p = top of stack */
11  i = head [p] ; /* i = youngest child of p */
12  if (i == -1)
13  {
14  top-- ; /* p has no unordered children left */
15  post [k++] = p ; /* node p is the kth postordered node */
16  }
17  else
18  {
19  head [p] = next [i] ; /* remove i from children of p */
20  stack [++top] = i ; /* start dfs on child node i */
21  }
22  }
23  return (k) ;
24 }
CS_INT cs_tdfs(CS_INT j, CS_INT k, CS_INT *head, const CS_INT *next, CS_INT *post, CS_INT *stack)
Definition: cs_tdfs.c:3
#define CS_INT
Definition: cs.h:627