BSD 4_4 release
[unix-history] / usr / src / old / refer / hunt / shell.c
CommitLineData
a860ef9e 1/*-
ad787160
C
2 * This module is believed to contain source code proprietary to AT&T.
3 * Use and redistribution is subject to the Berkeley Software License
4 * Agreement and your Software Agreement with AT&T (Western Electric).
a860ef9e
KB
5 */
6
9b0d0441 7#ifndef lint
ad787160 8static char sccsid[] = "@(#)shell.c 4.2 (Berkeley) 4/18/91";
a860ef9e
KB
9#endif /* not lint */
10
9b0d0441
BT
11/*
12 * SORTS UP.
13 * IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP
14 * THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP
15 */
16shell (n, comp, exch)
17int (*comp)(), (*exch)();
18{
19 int igap, iplusg, iex, i, imax;
20 igap=n;
21 while (igap > 1)
22 {
23 igap /= 2;
24 imax = n-igap;
25 do
26 {
27 iex=0;
28 for(i=0; i<imax; i++)
29 {
30 iplusg = i + igap;
31 if ((*comp) (i, iplusg) ) continue;
32 (*exch) (i, iplusg);
33 iex=1;
34 }
35 }
36 while (iex>0);
37 }
38}