xref: /illumos-gate/usr/src/cmd/refer/shell.c (revision 35551380472894a564e057962b701af78f719377)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 /*
18  * SORTS UP.
19  * IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP
20  * THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP
21  */
22 void
23 shell(int n, int (*comp)(), int (*exch)())
24 {
25 	int igap, iplusg, iex, i, imax;
26 	igap = n;
27 	while (igap > 1) {
28 		igap /= 2;
29 		imax = n-igap;
30 		do {
31 			iex = 0;
32 			for (i = 0; i < imax; i++) {
33 				iplusg = i + igap;
34 				if ((*comp)(i, iplusg)) continue;
35 				(*exch) (i, iplusg);
36 				iex = 1;
37 			}
38 		}
39 		while (iex > 0)
40 			;
41 	}
42 }
43