Initial Commit
This commit is contained in:
BIN
Submissions/Final/Q4.docx
Normal file
BIN
Submissions/Final/Q4.docx
Normal file
Binary file not shown.
23
Submissions/Final/Q4.java
Normal file
23
Submissions/Final/Q4.java
Normal file
@ -0,0 +1,23 @@
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class Q4 {
|
||||
public void removeLowestGrade () {
|
||||
if (head == null) {
|
||||
throw new NoSuchElementException("List was empty");
|
||||
}
|
||||
if (head.next == null) {
|
||||
//if only one element
|
||||
head = null;
|
||||
}
|
||||
|
||||
GradeNode smallest = head;
|
||||
GradeNode index = head;
|
||||
while(index.next != null) {
|
||||
if (index.next.grade < smallest.grade) {
|
||||
smallest = index;
|
||||
}
|
||||
index = index.next;
|
||||
}
|
||||
smallest.next = smallest.next.next;
|
||||
}
|
||||
}
|
BIN
Submissions/Final/Q5.docx
Normal file
BIN
Submissions/Final/Q5.docx
Normal file
Binary file not shown.
56
Submissions/Final/Q5.java
Normal file
56
Submissions/Final/Q5.java
Normal file
@ -0,0 +1,56 @@
|
||||
public class Q5 {
|
||||
|
||||
//first solution
|
||||
public static int countInside (int[][] map, int row, int col) {
|
||||
int initialCount = 0;
|
||||
for(int[] innerArray: map) {
|
||||
for(int val: innerArray) {
|
||||
if (val = 1)
|
||||
initialCount++;
|
||||
}
|
||||
}
|
||||
|
||||
countInsideRecursive(row, col, map);
|
||||
|
||||
int finalCount = 0;
|
||||
for(int[] innerArray: map) {
|
||||
for(int val: innerArray) {
|
||||
if (val = 1)
|
||||
finalCount++;
|
||||
}
|
||||
}
|
||||
return finalCount - initialCount;
|
||||
|
||||
}
|
||||
private static void countInsideRecursive(int row, int col, int[][] map) {
|
||||
map[row][col] = 1;
|
||||
if (room[row - 1][col] == 0) //up
|
||||
countInsideRecursive(row - 1, col, map);
|
||||
if (room[row + 1][col] == 0) //down
|
||||
countInsideRecursive(row + 1, col, map);
|
||||
if (room[row][col - 1] == 0) //left
|
||||
countInsideRecursive(row, col - 1, map);
|
||||
if (room[row][col + 1] == 0) //right
|
||||
countInsideRecursive(row, col+1, map);
|
||||
}
|
||||
|
||||
//better solution
|
||||
|
||||
private static int countInside(int row, int col, int[][] map) {
|
||||
map[row][col] = 1;
|
||||
int count = 0;
|
||||
if (room[row - 1][col] == 0) {//up
|
||||
count = 1 + countInside(row - 1, col, map);
|
||||
}
|
||||
if (room[row + 1][col] == 0) {//down
|
||||
count = 1 + countInside(row + 1, col, map);
|
||||
}
|
||||
if (room[row][col - 1] == 0) {//left
|
||||
count = 1 + countInside(row, col - 1, map);
|
||||
}
|
||||
if (room[row][col + 1] == 0) {//right
|
||||
count = 1 + countInside(row, col+1, map);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
BIN
Submissions/Final/Q8.docx
Normal file
BIN
Submissions/Final/Q8.docx
Normal file
Binary file not shown.
BIN
Submissions/Final/Q9.docx
Normal file
BIN
Submissions/Final/Q9.docx
Normal file
Binary file not shown.
9
Submissions/Final/Q9.java
Normal file
9
Submissions/Final/Q9.java
Normal file
@ -0,0 +1,9 @@
|
||||
public class Q9 {
|
||||
private void print(Node current) {
|
||||
if (current != null) {
|
||||
print(current.right);
|
||||
System.out.println(current.word);
|
||||
print(current.left);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user