xref: /titanic_52/usr/src/cmd/refer/shell.c (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 #pragma ident	"%Z%%M%	%I%	%E% SMI"
17 
18 /*
19  * SORTS UP.
20  * IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP
21  * THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP
22  */
23 shell (n, comp, exch)
24 int (*comp)(), (*exch)();
25 {
26 	int igap, iplusg, iex, i, imax;
27 	igap=n;
28 	while (igap > 1)
29 	{
30 		igap /= 2;
31 		imax = n-igap;
32 		do
33 		    {
34 			iex=0;
35 			for(i=0; i<imax; i++)
36 			{
37 				iplusg = i + igap;
38 				if ((*comp) (i, iplusg) ) continue;
39 				(*exch) (i, iplusg);
40 				iex=1;
41 			}
42 		}
43 		while (iex>0);
44 	}
45 }
46