



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Project; Class: Full Course Title: Program Design and Development; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Fall 2007;
Typology: Study Guides, Projects, Research
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Due Date: Thursday, 1-Nov-2007 @ 10:00 pm via WebCat
gcd(0,0) returns 0 gcd(12,0) returns 12 gcd(1,1) returns 1 gcd(2,4) returns 2 gcd(10,25) returns 5
reverseString(null) returns null reverseString("") returns "" reverseString("1") returns "1" reverseString("abc") returns "cba" reverseString(" W") returns "W " reverseString("kayak") returns "kayak" reverseString("recursion is fun!") returns "!nuf si noisrucer"
public class IntNode { public int data; public IntNode next; public IntNode(int value) { data = value; next = null; } public IntNode(int value, IntNode nextNode) { data = value; next = nextNode; } }
/** This method will see if the given row and column values in the given board are safe. If no other queens can reach the given square, this method returns true. Otherwise, it returns false. */ private static boolean isSafe(int row, int column, boolean[][] board) { // check row for (int i = 0; i < board.length; i++) { if(board[i][column] && i != row) return false; } //check column for (int i = 0; i < board[0].length ; i++) { if(board[row][i] && i != column) return false; } //check diagonal int r = row-1, c = column-1; while (r >= 0 && c >= 0) { if(board[r][c]) return false; r--; c--; } r = row+1; c = column+1; while (r < board.length && c < board[r].length) { if(board[r][c]) return false; r++; c++; } r = row+1; c = column-1; while (r < board.length && c >= 0) { if(board[r][c]) return false; r++; c--; } r = row-1; c = column+1; while (r >= 0 && c < board[r].length) { if(board[r][c]) return false; r--; c++; } return true; }