1*719Sceastha /*
2*719Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3*719Sceastha * Use is subject to license terms.
4*719Sceastha */
5*719Sceastha
60Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
70Sstevel@tonic-gate /* All Rights Reserved */
80Sstevel@tonic-gate
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
120Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate */
140Sstevel@tonic-gate
15*719Sceastha #pragma ident "%Z%%M% %I% %E% SMI"
160Sstevel@tonic-gate
170Sstevel@tonic-gate /*
180Sstevel@tonic-gate * SORTS UP.
190Sstevel@tonic-gate * IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP
200Sstevel@tonic-gate * THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP
210Sstevel@tonic-gate */
22*719Sceastha void
shell(int n,int (* comp)(),int (* exch)())23*719Sceastha shell(int n, int (*comp)(), int (*exch)())
240Sstevel@tonic-gate {
250Sstevel@tonic-gate int igap, iplusg, iex, i, imax;
26*719Sceastha igap = n;
27*719Sceastha while (igap > 1) {
280Sstevel@tonic-gate igap /= 2;
290Sstevel@tonic-gate imax = n-igap;
30*719Sceastha do {
31*719Sceastha iex = 0;
32*719Sceastha for (i = 0; i < imax; i++) {
330Sstevel@tonic-gate iplusg = i + igap;
34*719Sceastha if ((*comp)(i, iplusg)) continue;
350Sstevel@tonic-gate (*exch) (i, iplusg);
36*719Sceastha iex = 1;
370Sstevel@tonic-gate }
38*719Sceastha }
39*719Sceastha while (iex > 0)
40*719Sceastha ;
410Sstevel@tonic-gate }
420Sstevel@tonic-gate }
43