Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/refer/shell.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "refer.h"

void shell(int n, int (*comp)(int,int), void (*exch)(int,int))
/* SORTS UP.  IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP
  THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP */
{
	int	igap, iplusg, iex, i, imax;
	igap = n;
	while (igap > 1) {
		igap /= 2;
		imax = n - igap;
		do
		 {
			iex = 0;
			for (i = 0; i < imax; i++) {
				iplusg = i + igap;
				if ((*comp)(i, iplusg) ) 
					continue;
				(*exch)(i, iplusg);
				iex = 1;
			}
		} while (iex > 0);
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].