assn03
This commit is contained in:
12
.envrc
Normal file
12
.envrc
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
jabba() {
|
||||||
|
local fd3=$(mktemp /tmp/jabba-fd3.XXXXXX)
|
||||||
|
(
|
||||||
|
JABBA_SHELL_INTEGRATION=ON $HOME/.jabba/bin/jabba "$@" 3>|${fd3}
|
||||||
|
)
|
||||||
|
local exit_code=$?
|
||||||
|
eval $(cat ${fd3})
|
||||||
|
rm -f ${fd3}
|
||||||
|
return ${exit_code}
|
||||||
|
}
|
||||||
|
|
||||||
|
jabba use
|
||||||
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@@ -4,6 +4,20 @@
|
|||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Main",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "assn03.Main",
|
||||||
|
"projectName": "COMP210_238a5b6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "JavaWarmUp",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "assn02.JavaWarmUp",
|
||||||
|
"projectName": "COMP210_238a5b6"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "java",
|
"type": "java",
|
||||||
"name": "Current File",
|
"name": "Current File",
|
||||||
|
|||||||
13
Justfile
13
Justfile
@@ -1,12 +1,19 @@
|
|||||||
default: run
|
default: run
|
||||||
|
|
||||||
run file=(`find src -type f -printf '%T@ %p\n' | sort -n | cut -d " " -f 2- | tail -1`):
|
recentFile := `find src -type f -printf '%T@ %p\n' | sort -n | cut -d " " -f 2- | tail -1`
|
||||||
java {{file}}
|
recentFolder := `find src -type d -printf '%T@ %p\n' | sort -n | cut -d' ' -f 2- | sed 's/src\///' | tail -2 | head -1`
|
||||||
|
|
||||||
|
echo:
|
||||||
|
echo {{recentFile}}
|
||||||
|
echo {{recentFolder}}
|
||||||
|
|
||||||
|
run file=recentFile:
|
||||||
|
if [ -f ./src/{{recentFolder}}/Main.java ]; then java --enable-preview -XX:+ShowCodeDetailsInExceptionMessages -cp ./out {{recentFolder}}.Main; else java {{file}}; fi
|
||||||
|
|
||||||
all:
|
all:
|
||||||
for file in `find src -type f -printf '%T@ %p\n' | sort -n | cut -d " " -f 2-`; do just run $file; done
|
for file in `find src -type f -printf '%T@ %p\n' | sort -n | cut -d " " -f 2-`; do just run $file; done
|
||||||
|
|
||||||
zip folder=(`find src -type d -printf '%T@ %p\n' | sort -n | cut -d' ' -f 2- | sed 's/src\///' | tail -1`):
|
zip folder=recentFolder:
|
||||||
rm -rf ./zips/{{folder}}.zip
|
rm -rf ./zips/{{folder}}.zip
|
||||||
zip -r ./zips/{{folder}}.zip ./src/{{folder}}
|
zip -r ./zips/{{folder}}.zip ./src/{{folder}}
|
||||||
|
|
||||||
|
|||||||
353
src/assn03/LinkedList.java
Normal file
353
src/assn03/LinkedList.java
Normal file
@@ -0,0 +1,353 @@
|
|||||||
|
package assn03;
|
||||||
|
|
||||||
|
public class LinkedList<T> {
|
||||||
|
private Node<T> head = null;
|
||||||
|
private Node<T> tail = null;
|
||||||
|
private int size = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task1
|
||||||
|
* Remove the node at index i of the list.
|
||||||
|
* Note that the first element is at index 0
|
||||||
|
* If i is larger than the size of the list, throw an IndexOutOfBounds Exception
|
||||||
|
*
|
||||||
|
* ex: list: A -> B -> C -> D
|
||||||
|
* i: 1
|
||||||
|
* list after removeAtIndex: A -> C -> D
|
||||||
|
*
|
||||||
|
* @param i - index of node to remove
|
||||||
|
*/
|
||||||
|
public void removeAtIndex(int i) {
|
||||||
|
this.validIndex(i);
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
head = head.getNext();
|
||||||
|
size--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object node = this.get(i);
|
||||||
|
this.remove(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task2
|
||||||
|
* Return true if this linked list is equal to the list argument, false
|
||||||
|
* otherwise.
|
||||||
|
* Two lists are equal if they have the same size, and the same
|
||||||
|
* elements in the same order.
|
||||||
|
* ex: list: 1 -> 4 -> 2
|
||||||
|
* list2: 1 -> 4 -> 2
|
||||||
|
* return: true
|
||||||
|
*
|
||||||
|
* list: 1 -> 5
|
||||||
|
* list2: 2 -> 5
|
||||||
|
* return false;
|
||||||
|
*
|
||||||
|
* @param list2 - the list to compare with the current list
|
||||||
|
* @return true if the lists have the same elements in the same order, false
|
||||||
|
* otherwise
|
||||||
|
*/
|
||||||
|
public boolean isEqual(LinkedList list2) {
|
||||||
|
if (this.size() == list2.size()) {
|
||||||
|
for (int i = 0; i < this.size(); i++)
|
||||||
|
if (this.get(i) != list2.get(i))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task3
|
||||||
|
* Given a sorted linked list, remove the duplicate values from the list
|
||||||
|
* ex: list: 5 -> 6 -> 7 -> 7 -> 7 -> 8 -> 8 -> 9
|
||||||
|
* list after removeRepeats: 5 -> 6 -> 7 -> 8 -> 9
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void removeRepeats() {
|
||||||
|
if (this.size() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Node<T> previous = head;
|
||||||
|
for (int i = 1; i < this.size(); i++) {
|
||||||
|
Node<T> current = previous.getNext();
|
||||||
|
|
||||||
|
if (previous.getValue() == current.getValue()) {
|
||||||
|
this.removeAtIndex(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
previous = current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task4
|
||||||
|
* Reverse the list
|
||||||
|
*
|
||||||
|
* ex list: 10 -> 9 -> 8 -> 7
|
||||||
|
* list after reverse: 7 -> 8 -> 9 -> 10
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void reverse() {
|
||||||
|
if (this.size() <= 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Node<T> previous = null;
|
||||||
|
Node<T> current = head;
|
||||||
|
Node<T> next = null;
|
||||||
|
|
||||||
|
while (current != null) {
|
||||||
|
next = current.getNext();
|
||||||
|
current.setNext(previous);
|
||||||
|
previous = current;
|
||||||
|
current = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
head = previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task5
|
||||||
|
* Merge the given linked list2 into the current list. The 2 lists will always
|
||||||
|
* be
|
||||||
|
* either the same size, or the current list will be longer than list2.
|
||||||
|
* The examples below show how to handle each case.
|
||||||
|
*
|
||||||
|
* Note: Do NOT create and return a new list, merge the second list into the
|
||||||
|
* first one.
|
||||||
|
*
|
||||||
|
* ex: list: 1 -> 2 -> 3
|
||||||
|
* list2: 4 -> 5 -> 6
|
||||||
|
* return: 1 -> 4 -> 2 -> 5 -> 3 -> 6
|
||||||
|
*
|
||||||
|
* list: 1 -> 2 -> 3 -> 4
|
||||||
|
* list2: 5 -> 6
|
||||||
|
* return 1 -> 5 -> 2 -> 6 -> 3 -> 4
|
||||||
|
*
|
||||||
|
* @param list2
|
||||||
|
*/
|
||||||
|
public void merge(LinkedList list2) {
|
||||||
|
if (this.size() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Node<T> current = head;
|
||||||
|
Node<T> current2 = list2.getHead();
|
||||||
|
Node<T> next = null;
|
||||||
|
Node<T> next2 = null;
|
||||||
|
|
||||||
|
while (current != null && current2 != null) {
|
||||||
|
next = current.getNext();
|
||||||
|
next2 = current2.getNext();
|
||||||
|
|
||||||
|
current.setNext(current2);
|
||||||
|
current2.setNext(next);
|
||||||
|
|
||||||
|
current = next;
|
||||||
|
current2 = next2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Implementations below are being given to you. Do not modify below this. */
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return size == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
head = null;
|
||||||
|
tail = null;
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(Object element) {
|
||||||
|
Node<T> current = head;
|
||||||
|
while (current != null) {
|
||||||
|
if (current.getValue().equals(element)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
current = current.getNext();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T[] toArray() {
|
||||||
|
T[] arr = (T[]) new Object[size()];
|
||||||
|
Node<T> current = head;
|
||||||
|
int i = 0;
|
||||||
|
if (isEmpty()) {
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
while (current != null) {
|
||||||
|
arr[i] = current.getValue();
|
||||||
|
current = current.getNext();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Object element) {
|
||||||
|
Node<T> newNode = new NodeImpl<T>((T) element, null);
|
||||||
|
if (isEmpty()) {
|
||||||
|
head = newNode;
|
||||||
|
tail = newNode;
|
||||||
|
size++;
|
||||||
|
} else {
|
||||||
|
tail.setNext(newNode);
|
||||||
|
tail = newNode;
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean remove(Object element) {
|
||||||
|
Node<T> current = head;
|
||||||
|
if (isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (current.getValue() == element) {
|
||||||
|
head = head.getNext();
|
||||||
|
size--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
while (current.getNext().getValue() != element) {
|
||||||
|
current = current.getNext();
|
||||||
|
if (current == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (current.getNext().getNext() == null) {
|
||||||
|
tail = current;
|
||||||
|
}
|
||||||
|
current.setNext(current.getNext().getNext());
|
||||||
|
size--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(int index) {
|
||||||
|
validIndex(index);
|
||||||
|
Node<T> current = head;
|
||||||
|
int i = 0;
|
||||||
|
while (i < index) {
|
||||||
|
current = current.getNext();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return current.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T set(int index, Object element) {
|
||||||
|
validIndex(index);
|
||||||
|
Node<T> current = head;
|
||||||
|
T prevValue = null;
|
||||||
|
int i = 0;
|
||||||
|
if (index == 0) {
|
||||||
|
prevValue = head.getValue();
|
||||||
|
head.setValue((T) element);
|
||||||
|
} else {
|
||||||
|
while (current != null) {
|
||||||
|
if (i == index) {
|
||||||
|
prevValue = current.getValue();
|
||||||
|
current.setValue((T) element);
|
||||||
|
return prevValue;
|
||||||
|
}
|
||||||
|
current = current.getNext();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return prevValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int index, Object element) {
|
||||||
|
if (index > size) {
|
||||||
|
validIndex(index);
|
||||||
|
}
|
||||||
|
Node<T> current = head;
|
||||||
|
int i = 0;
|
||||||
|
if (index == 0) {
|
||||||
|
if (isEmpty()) {
|
||||||
|
add(element);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Node<T> newNode = new NodeImpl<T>((T) element, head.getNext());
|
||||||
|
head = newNode;
|
||||||
|
size++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (index == size) {
|
||||||
|
add(element);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (current != null) {
|
||||||
|
if (i == (index - 1)) {
|
||||||
|
Node<T> temp = current.getNext();
|
||||||
|
Node<T> newNode = new NodeImpl<T>((T) element, temp);
|
||||||
|
current.setNext(newNode);
|
||||||
|
size++;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
current = current.getNext();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int indexOf(Object element) {
|
||||||
|
Node<T> current = head;
|
||||||
|
int index = 0;
|
||||||
|
while (current != null) {
|
||||||
|
if (current.getValue().equals((T) element)) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
current = current.getNext();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int lastIndexOf(Object element) {
|
||||||
|
Node<T> current = head;
|
||||||
|
int index = -1;
|
||||||
|
int i = 0;
|
||||||
|
while (current != null) {
|
||||||
|
if (current.getValue().equals((T) element)) {
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
current = current.getNext();
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validIndex(int i) {
|
||||||
|
if (i < 0 || i >= size) {
|
||||||
|
throw new IndexOutOfBoundsException("Invalid index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node<T> getHead() {
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String list = "";
|
||||||
|
Node<T> current = head;
|
||||||
|
while (current != null) {
|
||||||
|
if (current.getNext() == null)
|
||||||
|
list += current.getValue();
|
||||||
|
else
|
||||||
|
list += current.getValue() + " -> ";
|
||||||
|
current = current.getNext();
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
135
src/assn03/Main.java
Normal file
135
src/assn03/Main.java
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
package assn03;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
LinkedList<Integer> defaultList = new LinkedList<Integer>();
|
||||||
|
defaultList.add(10);
|
||||||
|
defaultList.add(20);
|
||||||
|
defaultList.add(60);
|
||||||
|
defaultList.add(30);
|
||||||
|
System.out.println("list = " + defaultList.toString());
|
||||||
|
System.out.println("size of list = " + defaultList.size());
|
||||||
|
System.out.println("list contains 10?: " + defaultList.contains(10)); // implemented
|
||||||
|
System.out.println("list contains 50?: " + defaultList.contains(50));
|
||||||
|
System.out.println("set element at index 2 to be 10");
|
||||||
|
defaultList.set(2, 10);
|
||||||
|
System.out.println("get element at index 2 = " + defaultList.get(2));
|
||||||
|
System.out.println("list = " + defaultList.toString());
|
||||||
|
System.out.println("Last Index of element 10 in list = " + defaultList.lastIndexOf(10));
|
||||||
|
|
||||||
|
defaultList.remove(20);
|
||||||
|
System.out.println("list after removing 20 = " + defaultList.toString());
|
||||||
|
|
||||||
|
int indexOf30 = defaultList.indexOf(30);
|
||||||
|
System.out.println("index of '30' = " + indexOf30);
|
||||||
|
|
||||||
|
// Test task 1
|
||||||
|
LinkedList<Integer> task1List1 = new LinkedList<Integer>();
|
||||||
|
task1List1.add(1);
|
||||||
|
task1List1.add(4);
|
||||||
|
task1List1.add(2);
|
||||||
|
System.out.println("task1List1 = " + task1List1.toString());
|
||||||
|
task1List1.removeAtIndex(1);
|
||||||
|
System.out.println("Task 1: task1List1 after removing index 1 = " + task1List1.toString());
|
||||||
|
|
||||||
|
LinkedList<Integer> task1List2 = new LinkedList<Integer>();
|
||||||
|
task1List2.add(1);
|
||||||
|
task1List2.add(4);
|
||||||
|
task1List2.add(2);
|
||||||
|
System.out.println("task1List2 = " + task1List2.toString());
|
||||||
|
task1List2.removeAtIndex(0);
|
||||||
|
System.out.println("Task 1: task1List2 after removing index 0 = " + task1List2.toString());
|
||||||
|
|
||||||
|
LinkedList<Integer> task1List3 = new LinkedList<Integer>();
|
||||||
|
task1List3.add(1);
|
||||||
|
task1List3.add(4);
|
||||||
|
task1List3.add(2);
|
||||||
|
System.out.println("task1List3 = " + task1List3.toString());
|
||||||
|
try {
|
||||||
|
task1List3.removeAtIndex(3);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("task1List3 = successfully failed to remove index 3 - " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test task 2
|
||||||
|
LinkedList<Integer> task2List1 = new LinkedList<Integer>();
|
||||||
|
task2List1.add(1);
|
||||||
|
task2List1.add(4);
|
||||||
|
task2List1.add(2);
|
||||||
|
System.out.println("task2List1 = " + task2List1.toString());
|
||||||
|
|
||||||
|
LinkedList<Integer> task2List2 = new LinkedList<Integer>();
|
||||||
|
task2List2.add(1);
|
||||||
|
task2List2.add(4);
|
||||||
|
task2List2.add(2);
|
||||||
|
System.out.println("task2List2 = " + task2List2.toString());
|
||||||
|
|
||||||
|
System.out.println("Task 2: task2List1 equals task2List2? " + task2List1.isEqual(task2List2));
|
||||||
|
|
||||||
|
LinkedList<Integer> task2List3 = new LinkedList<Integer>();
|
||||||
|
task2List3.add(1);
|
||||||
|
task2List3.add(5);
|
||||||
|
System.out.println("task2List3 = " + task2List3.toString());
|
||||||
|
|
||||||
|
System.out.println("Task 2: task2List1 equals task2List3? " + task2List1.isEqual(task2List3));
|
||||||
|
|
||||||
|
// Test task 3
|
||||||
|
LinkedList<Integer> task3List1 = new LinkedList<Integer>();
|
||||||
|
task3List1.add(1);
|
||||||
|
task3List1.add(2);
|
||||||
|
task3List1.add(2);
|
||||||
|
task3List1.add(2);
|
||||||
|
task3List1.add(2);
|
||||||
|
task3List1.add(3);
|
||||||
|
task3List1.add(3);
|
||||||
|
task3List1.add(3);
|
||||||
|
task3List1.add(4);
|
||||||
|
System.out.println("task3List1 before removing repeats = " + task3List1.toString());
|
||||||
|
task3List1.removeRepeats();
|
||||||
|
System.out.println("task3List1 after removing repeats = " + task3List1.toString());
|
||||||
|
|
||||||
|
// Test task 4
|
||||||
|
LinkedList<Integer> task4List = new LinkedList<Integer>();
|
||||||
|
task4List.add(1);
|
||||||
|
task4List.add(2);
|
||||||
|
task4List.add(3);
|
||||||
|
task4List.add(4);
|
||||||
|
System.out.println("task4List before reversing = " + task4List.toString());
|
||||||
|
task4List.reverse();
|
||||||
|
System.out.println("task4List after reversing = " + task4List.toString());
|
||||||
|
|
||||||
|
// Test task 5
|
||||||
|
LinkedList<Integer> task5List1 = new LinkedList<Integer>();
|
||||||
|
task5List1.add(1);
|
||||||
|
task5List1.add(2);
|
||||||
|
task5List1.add(3);
|
||||||
|
|
||||||
|
LinkedList<Integer> task5List2 = new LinkedList<Integer>();
|
||||||
|
task5List2.add(4);
|
||||||
|
task5List2.add(5);
|
||||||
|
task5List2.add(6);
|
||||||
|
|
||||||
|
System.out.println("task5List1 = " + task5List1.toString());
|
||||||
|
System.out.println("task5List2 = " + task5List2.toString());
|
||||||
|
|
||||||
|
task5List1.merge(task5List2);
|
||||||
|
System.out.println("task5List1 after merging task5List2 = " + task5List1.toString());
|
||||||
|
|
||||||
|
LinkedList<Integer> task5List3 = new LinkedList<Integer>();
|
||||||
|
task5List3.add(1);
|
||||||
|
task5List3.add(2);
|
||||||
|
task5List3.add(3);
|
||||||
|
task5List3.add(4);
|
||||||
|
|
||||||
|
LinkedList<Integer> task5List4 = new LinkedList<Integer>();
|
||||||
|
task5List4.add(5);
|
||||||
|
task5List4.add(6);
|
||||||
|
|
||||||
|
System.out.println("task5List3 = " + task5List3.toString());
|
||||||
|
System.out.println("task5List4 = " + task5List4.toString());
|
||||||
|
|
||||||
|
task5List3.merge(task5List4);
|
||||||
|
System.out.println("task5List3 after merging task5List4 = " + task5List3.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/assn03/Node.java
Normal file
16
src/assn03/Node.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package assn03;
|
||||||
|
|
||||||
|
public interface Node<T> {
|
||||||
|
|
||||||
|
T getValue();
|
||||||
|
|
||||||
|
void setValue(T value);
|
||||||
|
|
||||||
|
Node<T> getNext();
|
||||||
|
|
||||||
|
void setNext(Node<T> next);
|
||||||
|
|
||||||
|
default boolean hasNext() {
|
||||||
|
return (getNext() != null);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/assn03/NodeImpl.java
Normal file
32
src/assn03/NodeImpl.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package assn03;
|
||||||
|
|
||||||
|
public class NodeImpl<T> implements Node<T> {
|
||||||
|
|
||||||
|
private T _value;
|
||||||
|
private Node<T> _next;
|
||||||
|
|
||||||
|
public NodeImpl(T value, Node<T> next) {
|
||||||
|
_value = value;
|
||||||
|
_next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getValue() {
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(T value) {
|
||||||
|
_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Node<T> getNext() {
|
||||||
|
return _next;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNext(Node<T> next) {
|
||||||
|
_next = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user