#include	"colltbl.h"

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident "$Header: sortlist.c 1.1 89/10/09 $@(#)nls:sortlist.c	1.1 88/01/06 AT&T UEL"


SYMNODE
*sortlist(start, end)
SYMNODE	*start, *end;
{
	SYMNODE	*cp, *np, *lp, *save_prev, *save_max;

	if (start->thread == (SYMNODE *)NULL)
		return(start);
	lp = end;
	while(start->thread != lp)  {
		cp = save_max = start;
		while (cp != lp)	{
			np = cp->thread;
			if (GT(np->name, save_max->name))   {
				save_prev = cp;
				save_max = np;
			}
			if (np->thread == lp)	{
				if (save_max == start) {
					if (start->thread != np)
						np->thread = start->thread;
					else	cp = np;
					start = np;
				}
				else  {
					save_prev->thread = np;
					if (cp == save_max)
						cp = np;
					else	np->thread = save_max->thread;
				}
				cp->thread = save_max;
				save_max->thread = lp;
				lp = save_max;
			}
		cp = cp->thread;
		}
	}
	return(start);
}
