c++, data structure
Replace the 256 state table with a 20 state table.Replace the table look up with a table search.
Cargo.cpp
———————-
#include “Cargo.h”
int Cargo::charToCargo(char cargo)
{
switch(cargo)
{
case ‘w’: case ‘W’:
return WOLF;
case ‘s’: case ‘S’:
return SHOWMAN;
case ‘g’: case ‘G’:
return GOAT;
case ‘c’: case ‘C’:
return CABBAGES;
default:
return NOCARGO;
}
}
char Cargo::cargoToChar(int cargo)
{
switch(cargo)
{
case WOLF:
return ‘W’;
case SHOWMAN:
return ‘S’;
case GOAT:
return ‘G’;
case CABBAGES:
return ‘C’;
case NOCARGO:
return ‘N’;
default:
return ‘B’;
}
}
bool Cargo::isCargo(char candidate)
{
switch(candidate)
{
case ‘w’: case ‘W’: