// FILE: itemtool.tem // IMPLEMENTS: The three template functions of a small toolkit to manipulate // items (see itemtool.h). Note that this file is not compiled on its own. // Instead, this file is included with an include directive at the bottom of itemtool.h. #include // Provides assert #include // Provides size_t template Item maximal(Item a, Item b) { if (a > b) return a; else return b; } template size_t index_of_maximal(const Item data[ ], SizeType n) // Library facilities used: assert.h, stdlib.h { size_t answer; size_t i; assert(n > 0); answer = 0; for (i = 1; i < n; i++) { if (data[answer] < data[i]) answer = i; // data[answer] is now biggest from data[0]..data[i] } return answer; } template void ordered_insert(Item data[ ], SizeType n, Item entry) // Library functions used: stdlib.h { size_t i; for (i = n; (i > 0) && (data[i-1] > entry); i--) data[i] = data[i-1]; data[i] = entry; }