#include "stdstuff.h" #include "Time.h" #include "AllTime.h" AllTimeList::AllTimeList (int capacity) { // ****** } AllTimeList::~AllTimeList () { // ****** } static String2002 standardize (const String2002 &name) { int i; String2002 result; enum { justStarting, withinBlanks, withinWord } state = justStarting; for (i = 0; i < name.length(); i++) { if (name[i] == ' ') { // if we're justStarting, nothing has changed. // otherwise we've just begun to process embedded blanks. if (state != justStarting) state = withinBlanks; } else { if (state != withinWord) { // first letter of a word if (state == withinBlanks) result += ' '; result += (char) toupper(name[i]); } else { result += (char) tolower(name[i]); } state = withinWord; } } return result; } // returns a value between 0 and "tableSize - 1" int AllTimeList::hash (const String2002 &name) const { int total = 0, i, multiplier; for (i = 0; i < name.length(); i++) { if ((i % 4) == 0) { multiplier = 1; } total += name[i] * multiplier; multiplier *= 128; // 2 ** 7 } return total % tableSize; } // this is just a standard insert into a doubly linked list. void AllTimeList::addNodeToList (Node *node) { Node *p, *c; p = NULL; c = fastest; while (c != NULL && (c -> bestTime < node -> bestTime)) { p = c; c = c -> next; } node -> prior = p; node -> next = c; if (p == NULL) { fastest = node; } else { p -> next = node; } if (c == NULL) { slowest = node; } else { c -> prior = node; } } void AllTimeList::moveNodeIfNecessary (Node* node) { // ****** } void AllTimeList::add (const String2002 &name, const Time &bestTime) { // ****** } void AllTimeList::reportTime (const String2002 &name, const Time &time) { // ****** } Time AllTimeList::lookupTime (const String2002 &name) const { // ****** } bool AllTimeList::startWalk (String2002 &name, Time &time) { if ((walkPosition = fastest) == NULL) return false; walkInProgress = true; name = walkPosition -> name; time = walkPosition -> bestTime; return true; } bool AllTimeList::continueWalk (String2002 &name, Time &time) { if (!walkInProgress) { throw range_error ("AllTimeList::continueWalk - invalid call"); } if ((walkPosition = walkPosition -> next) == NULL ) { walkInProgress = false; // we've come to the end of the road return false; } name = walkPosition -> name; time = walkPosition -> bestTime; return true; }