Go to the documentation of this file.00001 #include "cs.h"
00002
00003 int *cs_post (const int *parent, int n)
00004 {
00005 int j, k = 0, *post, *w, *head, *next, *stack ;
00006 if (!parent) return (NULL) ;
00007 post = (int*) cs_malloc (n, sizeof (int)) ;
00008 w = (int*)cs_malloc (3*n, sizeof (int)) ;
00009 if (!w || !post) return (cs_idone (post, NULL, w, 0)) ;
00010 head = w ; next = w + n ; stack = w + 2*n ;
00011 for (j = 0 ; j < n ; j++) head [j] = -1 ;
00012 for (j = n-1 ; j >= 0 ; j--)
00013 {
00014 if (parent [j] == -1) continue ;
00015 next [j] = head [parent [j]] ;
00016 head [parent [j]] = j ;
00017 }
00018 for (j = 0 ; j < n ; j++)
00019 {
00020 if (parent [j] != -1) continue ;
00021 k = cs_tdfs (j, k, head, next, post, stack) ;
00022 }
00023 return (cs_idone (post, NULL, w, 1)) ;
00024 }