File:  [Research Unix] / researchv10no / cmd / cfront / libstring / testIt.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

/* unique word count */
#include "pair_list.h"

listoutimplement(pair)

main()
{
	String	s;
	pair_list	myList;
	/* input */
	while (cin >> s) {
		pair	p(s, 1);
		myList.put(p);
	}
	/* (bubble) sort */
	int swapFlag;
	if ( myList )
		do {
			swapFlag = FALSE;
			pair_list_iterator	it(myList);
			pair	x;
			pair	*y;
			while ( it.nextX(x) && it.peekX(y) ) {
				if ( x.name > y->name ) {
					it.remove();
					it.next();
					it.r_insert(x);
					swapFlag = TRUE;
				} else if ( x.name == y->name ) {
					y->count += x.count;
					it.remove();	// remove x
				}
			}
		} while ( swapFlag );
	/* print result */
	myOut(cout, myList);
}

unix.superglobalmegacorp.com

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