19S-Section-Solution

# 19S-Section-Solution - CS106X Autumn 2009 Handout 19S Section Solution October 21st 22nd 2009 Solution 1 Creating Word Wreck Tangles bool

This preview shows pages 1–2. Sign up to view the full content.

CS106X Handout 19S Autumn 2009 October 21 st – 22 nd , 2009 Section Solution Solution 1: Creating Word Wreck Tangles bool IsReasonableToContinue(Grid<char>& board, Lexicon& lex, int row, int col) { string rowText; for (int c = 0; c <= col; c++) rowText += board[row][c]; if ((col == board.numCols() - 1) && !lex.containsWord(rowText)) return false; if ((col < board.numCols() - 1) && !lex.containsPrefix(rowText)) return false; string columnText; for (int r = 0; r <= row; r++) columnText += board.getAt(r, col); if ((row == board.numRows() - 1) && !lex.containsWord(columnText)) return false; if ((row < board.numRows() - 1) & !lex.containsPrefix(columnText)) return false; return true; } bool FindUnassignedLocation(Grid<char>& board, int& row, int& col) { for (row = 0; row < board.numRows(); row++) { for (col = 0; col < board.numCols(); col++) { if (board[row][col] == ' ') return true; } } return false; } bool CreateWreckTangle(Grid<char>& board, Lexicon& lex) { int row, col; if (!FindUnassignedLocation(board, row, col)) return true;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/07/2010 for the course CS 201 taught by Professor Selimaksoy during the Spring '09 term at Bilkent University.

### Page1 / 3

19S-Section-Solution - CS106X Autumn 2009 Handout 19S Section Solution October 21st 22nd 2009 Solution 1 Creating Word Wreck Tangles bool

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online