EVSL
1.1.0
EigenValues Slicing Library
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
EXTERNAL
CXSparse
Source
cs_post.c
Go to the documentation of this file.
1
#include "
cs.h
"
2
/* post order a forest */
3
CS_INT
*
cs_post
(
const
CS_INT
*parent,
CS_INT
n)
4
{
5
CS_INT
j, k = 0, *post, *w, *head, *next, *stack ;
6
if
(!parent)
return
(NULL) ;
/* check inputs */
7
post =
cs_malloc
(n,
sizeof
(
CS_INT
)) ;
/* allocate result */
8
w =
cs_malloc
(3*n,
sizeof
(
CS_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
}
cs_post
CS_INT * cs_post(const CS_INT *parent, CS_INT n)
Definition:
cs_post.c:3
cs_tdfs
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
cs.h
CS_INT
#define CS_INT
Definition:
cs.h:627
cs_malloc
void * cs_malloc(CS_INT n, size_t size)
Definition:
cs_malloc.c:10
cs_idone
CS_INT * cs_idone(CS_INT *p, cs *C, void *w, CS_INT ok)
Definition:
cs_util.c:98
Generated by
1.8.6