IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
shellSort_dh.c
00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 */
00042 
00043 /* shell sort adopted from Edmond Chow */
00044 
00045 #include "shellSort_dh.h"
00046 
00047 #undef __FUNC__
00048 #define __FUNC__ "shellSort_int"
00049 void
00050 shellSort_int (const int n, int *x)
00051 {
00052   START_FUNC_DH int m, max, j, k, itemp;
00053 
00054   m = n / 2;
00055   while (m > 0)
00056     {
00057       max = n - m;
00058       for (j = 0; j < max; j++)
00059     {
00060       for (k = j; k >= 0; k -= m)
00061         {
00062           if (x[k + m] >= x[k])
00063         break;
00064           itemp = x[k + m];
00065           x[k + m] = x[k];
00066           x[k] = itemp;
00067         }
00068     }
00069       m = m / 2;
00070     }
00071 END_FUNC_DH}
00072 
00073 #undef __FUNC__
00074 #define __FUNC__ "shellSort_float"
00075 void
00076 shellSort_float (const int n, double *x)
00077 {
00078   START_FUNC_DH int m, max, j, k;
00079   double itemp;
00080 
00081   m = n / 2;
00082   while (m > 0)
00083     {
00084       max = n - m;
00085       for (j = 0; j < max; j++)
00086     {
00087       for (k = j; k >= 0; k -= m)
00088         {
00089           if (x[k + m] >= x[k])
00090         break;
00091           itemp = x[k + m];
00092           x[k + m] = x[k];
00093           x[k] = itemp;
00094         }
00095     }
00096       m = m / 2;
00097     }
00098 END_FUNC_DH}
00099 
00100 
00101 #if 0
00102 #undef __FUNC__
00103 #define __FUNC__ "shellSort_int_float"
00104 void
00105 shellSort_int_float (int n, int *x, VAL_DH * xVals)
00106 {
00107   START_FUNC_DH int m, max, j, k, itemp;
00108   VAL_DH atemp;
00109 
00110   m = n / 2;
00111   while (m > 0)
00112     {
00113       max = n - m;
00114       for (j = 0; j < max; j++)
00115     {
00116       for (k = j; k >= 0; k -= m)
00117         {
00118           if (x[k + m] >= x[k])
00119         break;
00120           itemp = x[k + m];
00121           atemp = xVals[k + m];
00122           x[k + m] = x[k];
00123           /* xVals[k+m] = xVals[k]; */
00124           x[k] = itemp;
00125           xVals[k] = atemp;
00126         }
00127     }
00128       m = m / 2;
00129     }
00130 END_FUNC_DH}
00131 #endif
 All Classes Files Functions Variables Enumerations Friends