|
|
1.1 ! root 1: /* unique word count */ ! 2: #include "pair_list.h" ! 3: ! 4: listoutimplement(pair) ! 5: ! 6: main() ! 7: { ! 8: String s; ! 9: pair_list myList; ! 10: /* input */ ! 11: while (cin >> s) { ! 12: pair p(s, 1); ! 13: myList.put(p); ! 14: } ! 15: /* (bubble) sort */ ! 16: int swapFlag; ! 17: if ( myList ) ! 18: do { ! 19: swapFlag = FALSE; ! 20: pair_list_iterator it(myList); ! 21: pair x; ! 22: pair *y; ! 23: while ( it.nextX(x) && it.peekX(y) ) { ! 24: if ( x.name > y->name ) { ! 25: it.remove(); ! 26: it.next(); ! 27: it.r_insert(x); ! 28: swapFlag = TRUE; ! 29: } else if ( x.name == y->name ) { ! 30: y->count += x.count; ! 31: it.remove(); // remove x ! 32: } ! 33: } ! 34: } while ( swapFlag ); ! 35: /* print result */ ! 36: myOut(cout, myList); ! 37: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.