Amesos Package Browser (Single Doxygen Collection) Development
amesos_camd_postorder.c
Go to the documentation of this file.
00001 /* ========================================================================= */
00002 /* === CAMD_postorder ====================================================== */
00003 /* ========================================================================= */
00004 
00005 /* ------------------------------------------------------------------------- */
00006 /* CAMD, Copyright (c) Timothy A. Davis, Yanqing Chen,           */
00007 /* Patrick R. Amestoy, and Iain S. Duff.  See ../README.txt for License.     */
00008 /* email: davis at cise.ufl.edu    CISE Department, Univ. of Florida.        */
00009 /* web: http://www.cise.ufl.edu/research/sparse/camd                         */
00010 /* ------------------------------------------------------------------------- */
00011 
00012 /* Perform a postordering (via depth-first search) of an assembly tree. */
00013 
00014 #include "amesos_camd_internal.h"
00015 
00016 GLOBAL Int CAMD_postorder
00017 (
00018     Int j,      /* start at node j, a root of the assembly tree */
00019     Int k,      /* on input, next node is the kth node */
00020     Int n,      /* normal nodes 0 to n-1, place-holder node n */
00021     Int head [],    /* head of link list of children of each node */
00022     Int next [],    /* next[i] is the next child after i in link list */
00023     Int post [],    /* postordering, post [k] = p if p is the kth node */
00024     Int stack []    /* recursion stack */
00025 )
00026 {
00027     int i, p, top = 0 ;
00028     stack [0] = j ;   /* place j on the stack, maybe place-holder node n */
00029     while (top >= 0)    /* while (stack is not empty) */
00030     {
00031   p = stack [top] ; /* p = top of stack */
00032   i = head [p] ;    /* i = youngest child of p */
00033   if (i == -1)
00034   {
00035       top-- ;   /* p has no unordered children left */
00036       if (p != n)
00037       {
00038     /* node p is the kth postordered node.  Do not postorder the
00039      * place-holder node n, which is the root of a subtree
00040      * containing all dense and empty nodes. */
00041     post [k++] = p ;
00042       }
00043   }
00044   else
00045   {
00046       head [p] = next [i] ;   /* remove i from children of p */
00047       stack [++top] = i ;     /* start dfs on child node i */
00048   }
00049     }
00050     return (k) ;
00051 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines