/** * Inserts a ship to a LinkedList of ships. * If the node is not defined, the ship to insert is inserted. * Otherwise, the function is called recursively using the next node until the * ship can be inserted. * * @param node The node in which to check for the ability to insert. * @param toInsert The ship to be inserted. */ void insertShip(ship** node, ship* toInsert){ if(*node == NULL){ *node = toInsert; } else{ insertShip(&(*node)->next, toInsert); } }
void RandomSetShips::setShip(Ship::TubesShip nTubes, Board& board) { Ship ship(nTubes); if (checkShip(ship, board)) insertShip(ship, board); else setShip(nTubes, board); }
/** * Processes the user input file and creates a ship for each entry. * * @param fr File pointer to specified input file * @param head Pointer to pointer of list containing each ship on map * @param t Pointer to time_t containing simulator clock */ void processInput(FILE *fr, ship** head, time_t *t){ char line[80]; //Get the date. if((fgets(line, 80, fr) != NULL)){ struct tm timestamp; sscanf(line, "%d %d %d %d %d %d", ×tamp.tm_mday, ×tamp.tm_mon, ×tamp.tm_year, ×tamp.tm_hour, ×tamp.tm_min, ×tamp.tm_sec); timestamp.tm_year -= 1900; timestamp.tm_isdst = -1; *t = mktime(×tamp); } //Process ship entries. while(fgets(line, 80, fr) != NULL){ if(strcmp(line, "++++++++\n") != 0){ insertShip(head, createShip(line)); } } fclose(fr); }