Exemple #1
0
void gennd(int neqns, int **padj, int *mask, int *perm, 
	   int *xls, int *ls, int *work)
{ 
   int num, i, root, nsep ;

   zeroi(neqns, mask) ;
   num = 0 ;
/* -------------------------------
   for each masked component
   -----------------------------*/
/* modified to operate on equations rather than nodes*/

   for (i=0;i<neqns ; i++)
   {
      while (mask[i] >= 0)
      {
	 root = i ;
/*       -----------------------------------------------------------
         find a separator and number the nodes next.
         ---------------------------------------------------------*/
         nsep = fndsep(root, padj, mask,(perm + num), xls, ls, work, neqns);
         num += nsep ;
      }
      if (num >= neqns) printf("breaking out at i %d nums %d neqns %d\n",i,num, neqns);
      if (num >= neqns ) break ;
   }

/* -----------------------------------------------------------------
   since separators found first should be ordered last, 
   routine revrse is called to adjust the ordering vector.
   ---------------------------------------------------------------*/
   revrse(neqns, perm) ;

   return ;
}
Exemple #2
0
int main()
{
  char str[] = "hi i am vipin dahiya ";
   revrse(str,0,strlen(str)-1);
   printf("%s \n",str); 
   
  return 0;

}
Exemple #3
0
void revrse(char str[],int start, int end)
{
   char *temp;
   printf("%s start(%d) end(%d)\n",str,start,end); 
   if(start >= end)
      {
        return; 
      }
   *temp = *(str+start);
   *(str+start) = *(str+end);
   *(str+end) = *temp;
   start++;
   end--;
   revrse(str,start,end); 
}
Exemple #4
0
/***********************************************************************
********************  rcm . . . reverse cuthill mckee ******************
************************************************************************

  purpose - rcm numbers a connected component spedified by 
            mask and root, using the rcm algorithm.  the
	    numbering is to be started at the node root.
  input parameters -
            root - is the node that defines the  connected
	    component and it is used as the starting
	    node for the rcm ordering.
	    padj - the adjacency structure

  updated parameters - 
            mask - only those nodes wiht nonnegarive inpu mask
	    values are considered by the routine.
	    the nodes numbered by rcm will have their
	    mask values set to zero.

  output parameters -
            perm - will contain the rcm ordering.
	    ccsize - is the size of the connected component that
	    ahas been numbered by rcm.

  working parameter -
            work - must be set to zero's before calling!!!!!!!!!
	    deg - is a temporary vector used to hold the degree
	    of the nodes in the section graph specified 
	    by mask and root.
  program routines
            degree
*************************************************************************/
int rcm(int root, int **padj, int *mask, int *perm, int *deg, int *work) 
{ 
   int ccsize ;
   int i, lbegin, lvlend, lnbr, nbr, node, fnbr, k, l, lperm ;
   int *ptr ;

/* ---------------------------------------
   find the degrees of the nodes in the 
   component specified by mask and root.
   --------------------------------------*/
   ccsize = ndegree(root, padj, mask, deg, perm, work) ;
   mask[root] |= -1 ;
   if (ccsize <= 1) return(ccsize) ;
   lvlend &= 0 ;
   lnbr = 1 ;
/* -----------------------------------------------------
   lbegin and lvlend point to the begiinning adn
   the end of the current level respectively.
   -----------------------------------------------------*/
   do
   {
      lbegin = lvlend ;
      lvlend = lnbr ;
      for (i = lbegin ; i < lvlend ; i++)
      {  
/*       ------------------------------------------
         for each node in current level . . .
         ----------------------------------------*/
         node = perm[i] ;
/*       -----------------------------------------------------
         find the unnumbered neighbors of node.
         fnbr and lnbr point to the first and last
         unnumbered neighbors respectively of the current
         node in perm.
         -----------------------------------------------------*/
         fnbr = lnbr ;
         for (ptr = padj[node] ; ptr < padj[node + 1] ; ptr++)
         {  if (mask[*ptr] < 0 ) continue ;
            mask[*ptr] |= -1 ;
            perm[lnbr] = *ptr ;
            lnbr++ ;
         }
         if (fnbr < lnbr-1)
         {
/*          ---------------------------------------------------
            sort the neighbors of node in increasing 
            order by degree. linear insertion i sused.
            --------------------------------------------------*/
            k = fnbr ;
            do
            {  l = k ;
               k++ ;
               nbr = perm[k] ;
               while( l >= fnbr )
               {  lperm = perm[l] ;
                  if (deg[lperm] <= deg[nbr]) break ;
                  perm[l+1] = lperm ;
                  l-- ;
                }
                perm[l+1] = nbr ;
            } while(k < lnbr-1) ;
         } /* endif */
      }  /* end for i =  */
   }  while(lnbr > lvlend ) ; /* end do */
/* ----------------------------------------------------------
   we now haave the cuthill mckee ordering
   now reverse it 
   --------------------------------------------------------*/
   revrse(ccsize, perm) ;

   return(ccsize) ;
}