cs_post.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* post order a forest */
3 int *cs_post (const int *parent, int n)
4 {
5  int j, k = 0, *post, *w, *head, *next, *stack ;
6  if (!parent) return (NULL) ; /* check inputs */
7  post = (int*) cs_malloc (n, sizeof (int)) ; /* allocate result */
8  w = (int*)cs_malloc (3*n, sizeof (int)) ; /* get workspace */
9  if (!w || !post) return (cs_idone (post, NULL, w, 0)) ;
10  head = w ; next = w + n ; stack = w + 2*n ;
11  for (j = 0 ; j < n ; j++) head [j] = -1 ; /* empty linked lists */
12  for (j = n-1 ; j >= 0 ; j--) /* traverse nodes in reverse order*/
13  {
14  if (parent [j] == -1) continue ; /* j is a root */
15  next [j] = head [parent [j]] ; /* add j to list of its parent */
16  head [parent [j]] = j ;
17  }
18  for (j = 0 ; j < n ; j++)
19  {
20  if (parent [j] != -1) continue ; /* skip j if it is not a root */
21  k = cs_tdfs (j, k, head, next, post, stack) ;
22  }
23  return (cs_idone (post, NULL, w, 1)) ; /* success; free w, return post */
24 }
int * cs_post(const int *parent, int n)
Definition: cs_post.c:3
int * cs_idone(int *p, cs *C, void *w, int ok)
Definition: cs_util.c:97
int cs_tdfs(int j, int k, int *head, const int *next, int *post, int *stack)
Definition: cs_tdfs.c:3
void * cs_malloc(int n, size_t size)
Definition: cs_malloc.c:10
SegmentReturnType head(Index vecSize)
Definition: BlockMethods.h:781
Expression next(const Expression &arg)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:31