Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
external_packages
csparse
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
int
cs_tdfs
(
int
j,
int
k,
int
*
head
,
const
int
*
next
,
int
*post,
int
*stack)
4
{
5
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.h
cs_tdfs
int cs_tdfs(int j, int k, int *head, const int *next, int *post, int *stack)
Definition:
cs_tdfs.c:3
head
SegmentReturnType head(Index vecSize)
Definition:
BlockMethods.h:781
next
Expression next(const Expression &arg)
Definition:
acado_syntax.cpp:99
acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:31