1 /* 2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 7 /* All Rights Reserved */ 8 9 /* 10 * Copyright (c) 1980 Regents of the University of California. 11 * All rights reserved. The Berkeley software License Agreement 12 * specifies the terms and conditions for redistribution. 13 */ 14 15 /* 16 * SORTS UP. 17 * IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP 18 * THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP 19 */ 20 void 21 shell(int n, int (*comp)(), int (*exch)()) 22 { 23 int igap, iplusg, iex, i, imax; 24 igap = n; 25 while (igap > 1) { 26 igap /= 2; 27 imax = n-igap; 28 do { 29 iex = 0; 30 for (i = 0; i < imax; i++) { 31 iplusg = i + igap; 32 if ((*comp)(i, iplusg)) continue; 33 (*exch) (i, iplusg); 34 iex = 1; 35 } 36 } 37 while (iex > 0) 38 ; 39 } 40 } 41