File:  [Research Unix] / researchv10no / cmd / cfront / libstring / test12.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

// list test program.  Sorts standard input, prints with counts

#include "pair_list.h"

listoutimplement(pair)

pair_list
sort(pair_list aList)	// straight insertion
{
	pair_list_iterator	unsorted(aList);
	if ( unsorted.next() ) {
		pair	p;
		while ( unsorted.r_removeX(p) ) {
			pair_list_iterator	sorted = unsorted;
			pair	*q;  // pointer into sorted part
			while ( sorted.r_nextX(q) && q->name > p.name )
				;
			if ( q->name < p.name )
				sorted.next();   // back up
			else if ( q->name == p.name ) {
				q->count++;
				continue;
			}
			sorted.r_insert(p);
		}
	}
	return aList;
}
main()
{
	String	s;
	pair_list	myList;
	while (cin >> s)
		myList.put(pair(s));
	myOut(cout, sort(myList));
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.