diff --git a/.gitignore b/.gitignore
index 4042a10..c27dd3b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -200,3 +200,6 @@
/Semester 4/Assignments/DataStructures/target/
/MergeSort/target/
/Semester 3/Exams/ProgrammingExam2_CalebFontenot/target/
+/Semester 4/Assignments/HashMapASDV_Ant/nbproject/private/
+/Semester 4/Assignments/HashMapASDV_Ant/build/
+/Semester 4/Assignments/HashMapASDV_Ant/dist/
diff --git a/Semester 4/Assignments/HashMapASDV/pom.xml b/Semester 4/Assignments/HashMapASDV/pom.xml
new file mode 100644
index 0000000..01d5ebb
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV/pom.xml
@@ -0,0 +1,14 @@
+
+
+ 4.0.0
+ edu.slcc.asdv.caleb
+ HashMapASDV
+ 1.0-SNAPSHOT
+ jar
+
+ UTF-8
+ 20
+ 20
+ edu.slcc.asdv.caleb.hashmapasdv.HashMapASDV
+
+
\ No newline at end of file
diff --git a/Semester 4/Assignments/HashMapASDV/src/main/java/edu/slcc/asdv/caleb/hashmapasdv/HashMapASDV.java b/Semester 4/Assignments/HashMapASDV/src/main/java/edu/slcc/asdv/caleb/hashmapasdv/HashMapASDV.java
new file mode 100644
index 0000000..a888efc
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV/src/main/java/edu/slcc/asdv/caleb/hashmapasdv/HashMapASDV.java
@@ -0,0 +1,16 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ */
+
+package edu.slcc.asdv.caleb.hashmapasdv;
+
+/**
+ *
+ * @author caleb
+ */
+public class HashMapASDV {
+
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/Semester 4/Assignments/HashMapASDV_Ant/ListASDV.jar b/Semester 4/Assignments/HashMapASDV_Ant/ListASDV.jar
new file mode 100644
index 0000000..40b4913
Binary files /dev/null and b/Semester 4/Assignments/HashMapASDV_Ant/ListASDV.jar differ
diff --git a/Semester 4/Assignments/HashMapASDV_Ant/build.xml b/Semester 4/Assignments/HashMapASDV_Ant/build.xml
new file mode 100644
index 0000000..0d69356
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV_Ant/build.xml
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+ Builds, tests, and runs the project HashMapASDV_Ant.
+
+
+
diff --git a/Semester 4/Assignments/HashMapASDV_Ant/manifest.mf b/Semester 4/Assignments/HashMapASDV_Ant/manifest.mf
new file mode 100644
index 0000000..328e8e5
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV_Ant/manifest.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+X-COMMENT: Main-Class will be added automatically by build
+
diff --git a/Semester 4/Assignments/HashMapASDV_Ant/nbproject/build-impl.xml b/Semester 4/Assignments/HashMapASDV_Ant/nbproject/build-impl.xml
new file mode 100644
index 0000000..aa86cf0
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV_Ant/nbproject/build-impl.xml
@@ -0,0 +1,1771 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set src.dir
+ Must set test.src.dir
+ Must set build.dir
+ Must set dist.dir
+ Must set build.classes.dir
+ Must set dist.javadoc.dir
+ Must set build.test.classes.dir
+ Must set build.test.results.dir
+ Must set build.classes.excludes
+ Must set dist.jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No tests executed.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set JVM to use for profiling in profiler.info.jvm
+ Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ To run this application from the command line without Ant, try:
+
+ java -jar "${dist.jar.resolved}"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must set fix.includes
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set profile.class
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+ Some tests failed; see details above.
+
+
+
+ Must select some files in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+ Must select one file in the IDE or set test.class
+
+
+
+ Must select one file in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Semester 4/Assignments/HashMapASDV_Ant/nbproject/genfiles.properties b/Semester 4/Assignments/HashMapASDV_Ant/nbproject/genfiles.properties
new file mode 100644
index 0000000..7488dc6
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV_Ant/nbproject/genfiles.properties
@@ -0,0 +1,8 @@
+build.xml.data.CRC32=2e2f5c1c
+build.xml.script.CRC32=57d558c6
+build.xml.stylesheet.CRC32=f85dc8f2@1.108.0.48
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=2e2f5c1c
+nbproject/build-impl.xml.script.CRC32=4a925e01
+nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48
diff --git a/Semester 4/Assignments/HashMapASDV_Ant/nbproject/project.properties b/Semester 4/Assignments/HashMapASDV_Ant/nbproject/project.properties
new file mode 100644
index 0000000..a3bd69b
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV_Ant/nbproject/project.properties
@@ -0,0 +1,99 @@
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.processors.list=
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=HashMapASDV_Ant
+application.vendor=caleb
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+ ${run.classpath}
+debug.modulepath=\
+ ${run.modulepath}
+debug.test.classpath=\
+ ${run.test.classpath}
+debug.test.modulepath=\
+ ${run.test.modulepath}
+# Files in build.classes.dir which should be excluded from distribution jar
+dist.archive.excludes=
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/HashMapASDV_Ant.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+dist.jlink.dir=${dist.dir}/jlink
+dist.jlink.output=${dist.jlink.dir}/HashMapASDV_Ant
+endorsed.classpath=
+excludes=
+file.reference.ListASDV.jar=ListASDV.jar
+includes=**
+jar.compress=false
+javac.classpath=
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.external.vm=true
+javac.modulepath=
+javac.processormodulepath=
+javac.processorpath=\
+ ${javac.classpath}
+javac.source=20
+javac.target=20
+javac.test.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+javac.test.modulepath=\
+ ${javac.modulepath}
+javac.test.processorpath=\
+ ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.html5=false
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+# The jlink additional root modules to resolve
+jlink.additionalmodules=
+# The jlink additional command line parameters
+jlink.additionalparam=
+jlink.launcher=true
+jlink.launcher.name=HashMapASDV_Ant
+main.class=hashmapasdv_ant.HashMapASDV_Ant
+manifest.file=manifest.mf
+meta.inf.dir=${src.dir}/META-INF
+mkdist.disabled=false
+platform.active=default_platform
+run.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}:\
+ ${file.reference.ListASDV.jar}
+# Space-separated list of JVM arguments used when running the project.
+# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
+# To set system properties for unit tests define test-sys-prop.name=value:
+run.jvmargs=
+run.modulepath=\
+ ${javac.modulepath}
+run.test.classpath=\
+ ${javac.test.classpath}:\
+ ${build.test.classes.dir}
+run.test.modulepath=\
+ ${javac.test.modulepath}
+source.encoding=UTF-8
+src.dir=src
+test.src.dir=test
diff --git a/Semester 4/Assignments/HashMapASDV_Ant/nbproject/project.xml b/Semester 4/Assignments/HashMapASDV_Ant/nbproject/project.xml
new file mode 100644
index 0000000..6548cab
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV_Ant/nbproject/project.xml
@@ -0,0 +1,15 @@
+
+
+ org.netbeans.modules.java.j2seproject
+
+
+ HashMapASDV_Ant
+
+
+
+
+
+
+
+
+
diff --git a/Semester 4/Assignments/HashMapASDV_Ant/src/hashmapasdv_ant/EntryASDV.java b/Semester 4/Assignments/HashMapASDV_Ant/src/hashmapasdv_ant/EntryASDV.java
new file mode 100644
index 0000000..0bc80ee
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV_Ant/src/hashmapasdv_ant/EntryASDV.java
@@ -0,0 +1,91 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package hashmapasdv_ant;
+
+import java.util.Map.Entry;
+import java.util.Objects;
+
+/**
+ *
+ * @author caleb
+ */
+ class EntryASDV implements Entry, Comparable
+ {
+
+ K key;
+ V value;
+
+ public EntryASDV(K key, V value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public K getKey()
+ {
+ return key;
+ }
+
+ @Override
+ public V getValue()
+ {
+ return value;
+ }
+
+ @Override
+ public V setValue(V value)
+ {
+ V oldValue = this.value;
+ this.value = value;
+ return oldValue;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "EntryASDV{" + "key=" + key + ", value=" + value + '}';
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ final EntryASDV, ?> other = (EntryASDV, ?>) obj;
+ if (!Objects.equals(this.key, other.key))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @param o
+ * @return throws IllegalArgumentException if parameter class is not K
+ */
+ @Override
+ public int compareTo(K o)
+ {
+ if (getClass() != o.getClass())
+ {
+ throw new IllegalArgumentException("ellegal parameter " + o);
+ }
+ return ((Comparable) key).compareTo(o);
+ }
+
+ }
+
diff --git a/Semester 4/Assignments/HashMapASDV_Ant/src/hashmapasdv_ant/ListASDV.java b/Semester 4/Assignments/HashMapASDV_Ant/src/hashmapasdv_ant/ListASDV.java
new file mode 100644
index 0000000..61591aa
--- /dev/null
+++ b/Semester 4/Assignments/HashMapASDV_Ant/src/hashmapasdv_ant/ListASDV.java
@@ -0,0 +1,1713 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package hashmapasdv_ant;
+
+/**
+ *
+ * @author caleb
+ */
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.NoSuchElementException;
+import java.util.Queue;
+import java.util.Set;
+import java.util.function.Consumer;
+
+public class ListASDV
+ implements Serializable,
+ Cloneable,
+ Iterable,
+ Collection, Deque, List, Queue
+{
+
+ public Node head;
+ public Node tail;
+ BigInteger size;
+
+ public class Node
+ {
+
+ public E e;
+ public Node l;
+ public Node r;
+ }
+ public BigInteger sizeBigInteger()
+ {
+ return size;
+ }
+ /**
+ * Constructs an empty list.
+ */
+ public ListASDV()
+ {
+ size = new BigInteger("0");
+ }
+
+ /**
+ * Constructs a list containing the elements of the specified collection, in
+ * the order they are returned by the collection's iterator.
+ *
+ * @param c - the collection whose elements are to be placed into this list
+ * @throws NullPointerException - if the specified collection is null
+ */
+ public ListASDV(Collection extends E> c)
+ {
+ if (c == null)
+ {
+ throw new NullPointerException("Null parameter " + c);
+ }
+ this.addAll(c);
+ size.add(new BigInteger( Integer.toString(c.size())));
+ }
+
+ /**
+ * @return Iteraror with the implementation of: hasNext, next
+ * forEachRemaining
+ */
+ @Override
+ public Iterator iterator()
+ {
+ Iterator it = new Iterator()
+ {
+ Node trailNext = head;
+ @Override public boolean hasNext()
+ {
+ if (trailNext == null)
+ {
+ trailNext = head;
+ return false;
+ }
+ return true;
+ }
+ @Override public E next()
+ {
+ Node temp = trailNext;
+ trailNext = trailNext.r;
+ return temp.e;
+ }
+ /**
+ * Performs the given action for each remaining element until all
+ * elements have been processed or the action throws an exception.
+ *
+ * @param action has method accept(T t) which performs this
+ * operation on the given argument.
+ */
+ @Override public void forEachRemaining(Consumer super E> action)
+ {
+ //Node temp = trailNext;
+ //while (temp != null){action.accept(temp.e);temp = temp.r;}
+ while (hasNext()) action.accept( next() );
+ }
+ };
+ return it;
+ }
+
+ /**
+ * Inserts all of the elements in the specified collection into this list,
+ * starting at the specified position. Shifts the element currently at that
+ * position (if any) and any subsequent elements to the right (increases
+ * their indices). The new elements will appear in the list in the order
+ * that they are returned by the specified collection's iterator.
+ *
+ * @param index - index at which to insert the first element from the
+ * specified collection
+ * @param c - collection containing elements to be added to this list
+ * @return true if this list changed as a result of the call
+ * @throws IndexOutOfBoundsException - if the index is out of range (index
+ * LESS 0 || index GREATER size())
+ * @throws NullPointerException - if the specified collection is null
+ */
+ @Override
+ public boolean addAll(int index, Collection extends E> c)
+ {
+ if (index < 0 || index > size())
+ {
+ throw new IndexOutOfBoundsException("IndexOutOfBoundsException, index: " + index);
+ }
+ if (c == null)
+ {
+ throw new NullPointerException("Null parameter " + c);
+ }
+ Node temp = tail;
+ for (E e : c)
+ {
+ add(index++, e);
+ }
+ size.add(new BigInteger( Integer.toString(c.size())));
+
+ return temp != tail;
+ }
+
+ /**
+ * Returns the element at the specified position in this list.
+ *
+ * @param index - index of the element to return
+ * @return the element at the specified position in this list
+ * @throws IndexOutOfBoundsException - if the index is out of range (index
+ * LT 0 || index GE size())
+ */
+ @Override
+ public E get(int index)
+ {
+ if (index < 0 || index >= size())
+ {
+ throw new IndexOutOfBoundsException("Out of bounds: " + Integer.toString(index));
+ }
+
+ Node temp = head;
+ for (int i = 0; i < index; ++i)
+ {
+ temp = temp.r;
+ }
+ return temp.e;
+ }
+
+ /**
+ * Replaces the element at the specified position in this list with the
+ * specified element (optional operation).
+ *
+ * @param index - index of the element to replace
+ * @param element
+ * @return element - the element previously at the specified position
+ * @throws ClassCastException - if the class of the specified element
+ * prevents it from being added to this list
+ * @throws NullPointerException - if the specified element is null and this
+ * list does not permit null elements
+ * @throws IllegalArgumentException - if some property of the specified
+ * element prevents it from being added to this list
+ * @throws IndexOutOfBoundsException - if the index is out of range (index L
+ * 0 || index GE size())
+ */
+ @Override
+ public E set(int index, E element)
+ {
+
+ if (index < 0 || index >= size())
+ {
+ throw new IndexOutOfBoundsException("Out of bounds: " + Integer.toString(index));
+ }
+ if (element == null)
+ {
+ throw new NullPointerException("Null parameter " + element);
+ }
+
+ Node temp = head;
+ for (int i = 0; i < index; ++i)
+ {
+ temp = temp.r;
+ }
+ E e = temp.e;
+ temp.e = element;
+ return e;
+ }
+
+ /**
+ * Inserts the specified element at the specified position in this list.
+ * Shifts the element currently at that position (if any) and any subsequent
+ * elements to the right (adds one to their indices).
+ *
+ * @param index at which the specified element is to be inserted
+ * @param element - element to be appended to this list
+ * @throws IndexOutOfBoundsException - if the index is out of range (index L
+ * 0 || index G size())
+ */
+ @Override
+ public void add(int index, E element)
+ {
+ if (index < 0 || index > size())
+ {
+ throw new IndexOutOfBoundsException("Out of bounds: " + Integer.toString(index));
+ }
+ if (element == null)
+ {
+ throw new NullPointerException("Null parameter " + element);
+ }
+ Node newNode = new Node();
+ newNode.e = element;
+ if (head == null)
+ {
+ tail = head = newNode;
+ }
+ else
+ {
+ if (index == 0)//add in the front
+ {
+ newNode.r = head;
+ head.l = newNode;
+ head = newNode;
+ }
+ else if (index == size())//add in the end
+ {
+ newNode.l = tail;
+ tail.r = newNode;
+ tail = newNode;
+ }
+ else //add in the middle
+ {
+ Node temp = head;
+ for (int i = 0; i < index; ++i)
+ {
+ temp = temp.r;
+ }
+
+ newNode.r = temp;
+ newNode.l = temp.l;
+ temp.l.r = newNode;
+ temp.l = newNode;
+
+ }
+ }
+ size.add(new BigInteger( "1"));
+
+ }
+
+ /**
+ * Removes the element at the specified position in this list. Shifts any
+ * subsequent elements to the left (subtracts one from their indices).
+ * Returns the element that was removed from the list.
+ *
+ * @param index the index of the element to be removed
+ * @return the element previously at the specified position, null if empty
+ * list
+ * @throws IndexOutOfBoundsException - if the index is out of range (index
+ * LESS 0 or index GE size()
+ */
+ @Override
+ public E remove(int index)
+ {
+ if (index < 0 || index >= size())
+ {
+ throw new IndexOutOfBoundsException("Index Out of bounds exception : " + index);
+ }
+ if (size() == 0)
+ {
+ return null;
+ }
+ size.subtract(new BigInteger( "1"));
+ if (size() == 1 && index == 0)//special case just having 1 node
+ {
+ Node temp = head;
+ head = tail = null;
+ return temp.e;
+ }
+ else if (index == 0)//remove the first node
+ {
+ Node temp = head;
+ head = head.r;
+ head.l = null;
+ return temp.e;
+ }
+ else if (index == size() - 1)//remove last node
+ {
+ Node temp = tail;
+ tail = tail.l;
+ tail.r = null;
+ return temp.e;
+ }
+ else //remove in the middle
+ {
+ Node temp = head;
+ for (int i = 0; i < index; ++i)
+ {
+ temp = temp.r;
+ }
+
+ temp.l.r = temp.r;
+ temp.r.l = temp.l;
+ return temp.e;
+ }
+ }
+
+ /**
+ * Returns the index of the first occurrence of the specified element in
+ * this list, or -1 if this list does not contain the element. More
+ * formally, returns the lowest index i such that (o==null ? get(i)==null :
+ * o.equals(get(i))), or -1 if there is no such index.
+ *
+ *
+ * @param o - element to search for
+ * @return the index of the first occurrence of the specified element in
+ * this list, or -1 if this list does not contain the element
+ * @throws ClassCastException - if the type of the specified element is
+ * incompatible with this list (optional)
+ */
+ @Override
+ public int indexOf(Object o)
+ {
+ Iterator it = iterator();
+ int i = 0;
+ while (it.hasNext())
+ {
+ E e = it.next();
+ if (e.equals(o))
+ {
+ return i;
+ }
+ i++;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the index of the last occurrence of the specified element in this
+ * list, or -1 if this list does not contain the element. More formally,
+ * returns the highest index i such that (o==null ? get(i)==null :
+ * o.equals(get(i))), or -1 if there is no such index.
+ *
+ *
+ *
+ * @param o - element to search for
+ * @return the index of the last occurrence of the specified element in this
+ * list, or -1 if this list does not contain the element
+ * @throws:ClassCastException - if the type of the specified element is
+ * incompatible with this list (optional)
+ *
+ */
+ @Override
+ public int lastIndexOf(Object o)
+ {
+ Iterator it = this.descendingIterator();
+ int index = size() - 1;
+ while (it.hasNext())
+ {
+ if (it.next().equals(o))
+ {
+ return index;
+ }
+ --index;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns a list-iterator of the elements in this list (in proper
+ * sequence), starting at the specified position in the list. Obeys the
+ * general contract of List.listIterator(int). implements : hasNext, next,,
+ * previous, hasPrevious, nextIndex, previousIndex
+ *
+ * @param index - index of the first element to be returned from the
+ * list-iterator (by a call to next)
+ * @return a ListIterator of the elements in this list (in proper sequence),
+ * starting at the specified position in the list
+ *
+ * @throws IndexOutOfBoundsException - if the index is out of range (index L
+ * 0 || index G size())
+ */
+ @Override
+ public ListIterator listIterator(int index)
+ {
+ ListIterator it = new ListIterator()
+ {
+ Node trailNext = trailNextInitialize();
+ Node trailPrevious = trailNext.l;
+
+ int nextIndex = index;
+ int previousIndex = nextIndex - 1;
+
+ Node trailNextInitialize()
+ {
+ if (index < 0 || index > size())
+ {
+ throw new IndexOutOfBoundsException("ListIterator index out of bounds: " + index);
+ }
+ trailNext = head;
+ for (int i = 0; i < index; ++i)
+ {
+ trailNext = trailNext.r;
+ }
+ return trailNext;
+ }
+
+ /**
+ * Returns true if this list iterator has more elements when
+ * traversing the list in the forward direction. (In other words,
+ * returns true if next() would return an element rather than
+ * throwing an exception.)
+ *
+ * @return returns true if next() would return an element;
+ */
+ @Override
+ public boolean hasNext()
+ {
+ if (trailNext == null)
+ {
+ trailNext = head;
+ trailPrevious = trailNext.l;
+ nextIndex = 0;
+ previousIndex = -1;
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns the next element in the list and advances the cursor
+ * position. This method may be called repeatedly to iterate through
+ * the list, or intermixed with calls to previous() to go back and
+ * forth. (Note that alternating calls to next and previous will
+ * return the same element repeatedly.) Specified by: next in
+ * interface IteratorLE E>
+ * NoSuchElementException - if the iteration has no next element
+ *
+ * @return the next element in the list
+ * @throws NoSuchElementException if the iteration has no next element
+ */
+ @Override
+ public E next()
+ {
+ if ( trailNext == null )
+ throw new NoSuchElementException( "mo next element exists");
+
+ Node temp = trailNext;
+ trailPrevious = trailNext;
+ trailNext = trailNext.r;//advance the trailNext to the next node
+ previousIndex = nextIndex;//advance previous index to next
+ nextIndex++;// advance the next index
+
+ return temp.e;
+ }
+
+ @Override
+ public boolean hasPrevious()
+ {
+
+ if (trailPrevious == null)
+ {
+ trailNext = head;
+ trailPrevious = trailNext.l;
+ nextIndex = 0;
+ previousIndex = -1;
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public E previous()
+ {
+ if ( trailPrevious == null )
+ throw new NoSuchElementException( "no next element exists");
+
+ Node temp = trailPrevious;
+ trailNext = trailPrevious;
+ trailPrevious = trailPrevious.l;
+ nextIndex = previousIndex;
+ previousIndex--;
+ return temp.e;
+ }
+
+ @Override
+ public int nextIndex()
+ {
+ return nextIndex;
+ }
+
+ @Override
+ public int previousIndex()
+ {
+ return previousIndex;
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public void set(E e)
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public void add(E e)
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+ };
+ return it;
+ }
+
+ /**
+ * One line of code here. Call listIterator(0)
+ *
+ * @return ListIterator
+ */
+ @Override
+ public ListIterator listIterator()
+ {
+ return listIterator(0);
+ }
+
+ /**
+ * Returns a view of the portion of this list between the specified
+ * fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex
+ * are equal, the returned list is empty.) The returned list is backed by
+ * this list, so non-structural changes in the returned list are reflected
+ * in this list, and vice-versa. The returned list supports all of the
+ * optional list operations supported by this list.
+ *
+ *
+ * @param fromIndex - low endpoint (inclusive) of the subList
+ * @param toIndex - high endpoint (exclusive) of the subList
+ * @return a view of the specified range within this list
+ * @throws Throws: IndexOutOfBoundsException - for an illegal endpoint index
+ * value (fromIndex L 0 || toIndex G size || fromIndex > toIndex)
+ */
+ @Override
+ public List subList(int fromIndex, int toIndex)
+ {
+ if (fromIndex > toIndex || fromIndex < 0 || toIndex > size())
+ {
+ throw new IndexOutOfBoundsException("Index out of Bounds exception " + fromIndex + " " + toIndex);
+ }
+
+ E[] a = (E[]) new Object[0];
+ a = toArray(a);
+ a = Arrays.copyOfRange(a, fromIndex, toIndex);
+ return Arrays.asList(a);
+ }
+
+ @Override
+ public int size()
+ {
+ Node temp = head;
+ int count = 0;
+ while (temp != null)
+ {
+ count++;
+ temp = temp.r;
+ }
+ return count;
+ }
+
+ /**
+ * Tests is the list is empty
+ *
+ * @return true if the list is empty, false otherwise.
+ */
+ @Override
+ public boolean isEmpty()
+ {
+ return head == null;
+ }
+
+ /**
+ *
+ * Returns true if this list contains the specified element. More formally,
+ * returns true if and only if this list contains at least one element e
+ * such that (o==null ? e==null : o.equals(e)).
+ *
+ * @param o - element whose presence in this list is to be tested
+ * @return true if this list contains the specified element
+ * @throws ClassCastException - if the type of the specified element is
+ * incompatible with this list (optional)
+ */
+ @Override
+ public boolean contains(Object o)
+ {
+ Iterator it = this.iterator();
+ while (it.hasNext())
+ {
+ if (it.next().equals(o))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns an array containing all of the elements in this list in proper
+ * sequence (from first to last element).
+ *
+ * The returned array will be "safe" in that no references to it are
+ * maintained by this list. (In other words, this method must allocate a new
+ * array even if this list is backed by an array). The caller is thus free
+ * to modify the returned array.
+ *
+ * @return an array containing all of the elements in this list in proper
+ * sequence
+ */
+ @Override
+ public Object[] toArray()
+ {
+ Object[] ar = new Object[size()];
+ Iterator it = iterator();
+ int i = 0;
+ while (it.hasNext())
+ {
+ ar[i++] = it.next();
+ }
+ return ar;
+ }
+
+ /**
+ * Returns an array containing all of the elements in this list in proper
+ * sequence (from first to last element); the runtime type of the returned
+ * array is that of the specified array. If the list fits in the specified
+ * array, it is returned therein. Otherwise, a new array is allocated with
+ * the runtime type of the specified array and the size of this list. If the
+ * list fits in the specified array with room to spare (i.e., the array has
+ * more elements than the list), the element in the array immediately
+ * following the end of the list is set to null. (This is useful in
+ * determining the length of the list only if the caller knows that the list
+ * does not contain any null elements.)
+ *
+ * Like the toArray() method, this method acts as bridge between array-based
+ * and collection-based APIs. Further, this method allows precise control
+ * over the runtime type of the output array, and may, under certain
+ * circumstances, be used to save allocation costs.
+ *
+ * Suppose x is a list known to contain only strings. The following code can
+ * be used to dump the list into a newly allocated array of String: String[]
+ * y = x.toArray(new String[0]); Note that toArray(new Object[0]) is
+ * identical in function to toArray().
+ *
+ * Specified by: toArray in interface Collection Type Parameters: T - the
+ * runtime type of the array to contain the collection Parameters: a - the
+ * array into which the elements of this list are to be stored, if it is big
+ * enough; otherwise, a new array of the same runtime type is allocated for
+ * this purpose. Returns: an array containing the elements of this list
+ * Throws: ArrayStoreException - if the runtime type of the specified array
+ * is not a supertype of the runtime type of every element in this list
+ * NullPointerException - if the specified array is null
+ *
+ * @param - the runtime type of the array to contain the collection
+ * @param a - the array into which the elements of this list are to be
+ * stored, if it is big enough; otherwise, a new array of the same runtime
+ * type is allocated for this purpose.
+ *
+ * @return an array containing the elements of this list
+ * @throws ArrayStoreException - if the runtime type of the specified array
+ * is not a supertype of the runtime type of every element in this list
+ * @throws NullPointerException - if the specified array is null
+ */
+ @Override
+ public T[] toArray(T[] a)
+ {
+ if (a == null)
+ {
+ throw new NullPointerException("Null pointer exception: parameter is null");
+ }
+
+ if (a.length >= this.size())
+ {
+ Iterator it = iterator();
+ int i = 0;
+ while (it.hasNext())
+ {
+ T e = (T) it.next();
+ a[i++] = e;
+ }
+ return a;
+ }
+ else
+ {
+ T[] ar = Arrays.copyOf(a, size());
+
+ Iterator it = iterator();
+ int i = 0;
+ while (it.hasNext())
+ {
+ T e = (T) it.next();
+ ar[i++] = e;
+ }
+ return ar;
+ }
+
+ }
+
+ /**
+ * Appends the specified element to the end of this list. This method is
+ * equivalent to addLast(E).
+ *
+ * @param e element to be appended to this list
+ * @return true if this collection changed as a result of the call
+ */
+ @Override
+ public boolean add(E e)
+ {
+ Node newNode = new Node();
+ newNode.e = e;
+ if (head == null)
+ {
+ head = tail = newNode;
+ }
+ else
+ {
+ newNode.l = tail;
+ tail.r = newNode;
+ tail = newNode;
+ }
+ size.add(new BigInteger( "1"));
+ return true;
+ }
+
+ /**
+ * Removes a single instance of the specified element from this collection,
+ * if it is present (optional operation). More formally, removes an element
+ * e such that (o==null ? e==null : o.equals(e)), if this collection
+ * contains one or more such elements.
+ *
+ *
+ * @param o - element to be removed from this collection, if present
+ * @return true if this collection changed as a result of the call.
+ * @throws ClassCastException - if the type of the specified element is
+ * incompatible with this collection (optional)
+ * @throws NullPointerException - if the specified element is null and this
+ * collection does not permit null elements (optional)
+ */
+ @Override
+ public boolean remove(Object o)
+ {
+ if (o == null)
+ {
+ throw new NullPointerException("Null Pointer exception, cant pass null arguments");
+ }
+ Iterator it = this.iterator();
+ int pos = 0;
+ while (it.hasNext())
+ {
+ if (it.next().equals(o))
+ {
+ remove(pos);
+ return true;
+ }
+ pos++;
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if this collection contains all of the elements in the
+ * specified collection.
+ *
+ * @param c - collection to be checked for containment in this collection
+ * @return true if this collection contains all of the elements in the
+ * specified collection
+ * @throws ClassCastException - if the types of one or more elements in the
+ * specified collection are incompatible with this collection (optional)
+ * @throws NullPointerException - if the specified collection contains one
+ * or more null elements and this collection does not permit null elements
+ * (optional), or if the specified collection is null.
+ */
+ @Override
+ public boolean containsAll(Collection> c)
+ {
+ for (Object o : c)
+ {
+ if (contains(o) == false)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Appends all of the elements in the specified collection to the end of
+ * this list, in the order that they are returned by the specified
+ * collection's iterator. The behavior of this operation is undefined if the
+ * specified collection is modified while the operation is in progress.
+ * (Note that this will occur if the specified collection is this list, and
+ * it's nonempty.)
+ *
+ * @param c - collection containing elements to be added to this list
+ * @return true if this list changed as a result of the call
+ * @throws NullPointerException - if the specified collection is null
+ */
+ @Override
+ public boolean addAll(Collection extends E> c)
+ {
+ Node temp = tail;
+ for (E e : c)
+ {
+ add(e);
+ }
+ return temp != tail;
+ }
+
+ /**
+ * Removes from this list all of its elements that are contained in the
+ * specified collection (optional operation).
+ *
+ * @param c - collection containing elements to be removed from this list
+ * @return true if this list changed as a result of the call
+ * @throws ClassCastException - if the class of an element of this list is
+ * incompatible with the specified collection (optional)
+ */
+ @Override
+ public boolean removeAll(Collection> c)
+ {
+ Node temp1 = tail;
+ Node temp2 = head;
+ for (Object o : c)
+ {
+ while (this.remove(o))//remove all same occurances
+ ;
+ }
+
+ return temp1 != tail || temp2 != head;
+ }
+
+ /**
+ * Retains only the elements in this list that are contained in the
+ * specified collection (optional operation). In other words, removes from
+ * this list all of its elements that are not contained in the specified
+ * collection.
+ *
+ * @param c - collection containing elements to be retained in this list
+ * @return true if this list changed as a result of the call
+ * @throws ClassCastException - if the class of an element of this list is
+ * incompatible with the specified collection (optional)
+ */
+ @Override
+ public boolean retainAll(Collection> c)
+ {
+ ListASDV cloner = (ListASDV) this.clone();
+ cloner.removeAll(c);//cloner has elements to be deleted in the original list
+ Iterator it = cloner.iterator();
+ while (it.hasNext())
+ {
+ Object o = it.next();
+ while (this.remove(o));
+ }
+ return true;
+ }
+
+ /**
+ * Clears the list of all elements.
+ */
+ @Override
+ public void clear()
+ {
+ size = new BigInteger( "0");
+ head = tail = null;
+ }
+
+ /**
+ * Inserts the specified element at the beginning of this list.
+ *
+ * @param e - the element to add
+ */
+ @Override
+ public void addFirst(E e)
+ {
+ this.add(0, e);
+ }
+
+ /**
+ * Appends the specified element to the end of this list. This method is
+ * equivalent to add(E).
+ *
+ * @param e - the element to add
+ */
+ @Override
+ public void addLast(E e)
+ {
+ this.add(size(), e);
+ }
+
+ /**
+ * Inserts the specified element at the front of this deque unless it would
+ * violate capacity restrictions. When using a capacity-restricted deque,
+ * this method is generally preferable to the addFirst(E) method, which can
+ * fail to insert an element only by throwing an exception.
+ *
+ * Parameters: e - the element to add Returns: true if the element was added
+ * to this deque, else false Throws: ClassCastException - if the class of
+ * the specified element prevents it from being added to this deque
+ * NullPointerException - if the specified element is null and this deque
+ * does not permit null elements IllegalArgumentException - if some property
+ * of the specified element prevents it from being added to this deque
+ *
+ * @param e - the element to add
+ * @return true if the element was added to this deque, else false
+ * @throws ClassCastException if the class of the specified element prevents
+ * it from being added to this deque
+ * @throws IllegalArgumentException - if some property of the specified
+ * element prevents it from being added to this deque
+ */
+ @Override
+ public boolean offerFirst(E e)
+ {
+ addFirst(e);
+ return true;
+ }
+
+ /**
+ * Inserts the specified element at the end of this deque unless it would
+ * violate capacity restrictions. When using a capacity-restricted deque,
+ * this method is generally preferable to the addLast(E) method, which can
+ * fail to insert an element only by throwing an exception.
+ *
+ * Parameters: e - the element to add Returns: true if the element was added
+ * to this deque, else false Throws: ClassCastException - if the class of
+ * the specified element prevents it from being added to this deque
+ * NullPointerException - if the specified element is null and this deque
+ * does not permit null elements IllegalArgumentException - if some property
+ * of the specified element prevents it from being added to this deque
+ *
+ * @param e - the element to add
+ * @return true if the element was added to this deque, else false
+ * @throws ClassCastException - if the class of the specified element
+ * prevents it from being added to this deque
+ * @throws IllegalArgumentException - if some property of the specified
+ * element prevents it from being added to this deque *
+ */
+ @Override
+ public boolean offerLast(E e)
+ {
+ addLast(e);
+ return true;
+ }
+
+ /**
+ * E removeFirst()
+ *
+ * Retrieves and removes the first element of this deque. This method
+ * differs from pollFirst only in that it throws an exception if this deque
+ * is empty.
+ *
+ * @return the head of this deque
+ * @throws NoSuchElementException - if this deque is empty
+ */
+ @Override
+ public E removeFirst()
+ {
+ if (this.isEmpty())
+ {
+ throw new NoSuchElementException("list is empty");
+ }
+ return this.remove(0);
+ }
+
+ /**
+ * Retrieves and removes the last element of this deque. This method differs
+ * from pollLast only in that it throws an exception if this deque is empty.
+ *
+ * @return the tail of this deque
+ * @thows NoSuchElementException - if this deque is empty
+ */
+ @Override
+ public E removeLast()
+ {
+ if (this.isEmpty())
+ {
+ throw new NoSuchElementException("list is empty");
+ }
+ return this.remove(size() - 1);
+ }
+
+ /**
+ * Retrieves and removes the first element of this deque, or returns null if
+ * this deque is empty.
+ *
+ * @return the head of this deque, or null if this deque is empty
+ */
+ @Override
+ public E pollFirst()
+ {
+ return isEmpty() ? null : this.remove(0);
+ }
+
+ /**
+ * Retrieves and removes the last element of this deque, or returns null if
+ * this deque is empty.
+ *
+ * @return the tail of this deque, or null if this deque is empty
+ */
+ @Override
+ public E pollLast()
+ {
+ return isEmpty() ? null : this.remove(size() - 1);
+ }
+
+ /**
+ * Retrieves, but does not remove, the first element of this deque. This
+ * method differs from peekFirst only in that it throws an exception if this
+ * deque is empty.
+ *
+ * @return the head of this deque
+ * @throws NoSuchElementException - if this deque is empty
+ */
+ @Override
+ public E getFirst()
+ {
+ if (isEmpty())
+ {
+ throw new NoSuchElementException("The list is empty");
+ }
+
+ return head.e;
+ }
+
+ /**
+ * Retrieves, but does not remove, the last element of this deque. This
+ * method differs from peekLast only in that it throws an exception if this
+ * deque is empty.
+ *
+ * @return the tail of this deque
+ * @throws Throws: NoSuchElementException - if this deque is empty
+ */
+ @Override
+ public E getLast()
+ {
+ if (isEmpty())
+ {
+ throw new NoSuchElementException("The list is empty");
+ }
+ return tail.e;
+ }
+
+ /**
+ * Retrieves, but does not remove, the first element of this deque, or
+ * returns null if this deque is empty.
+ *
+ * @return the head of this deque, or null if this deque is empty
+ *
+ */
+ @Override
+ public E peekFirst()
+ {
+ return isEmpty() ? null : this.get(0);
+ }
+
+ /**
+ * Retrieves, but does not remove, the last element of this deque, or
+ * returns null if this deque is empty.
+ *
+ * @return the tail of this deque, or null if this deque is empty
+ */
+ @Override
+ public E peekLast()
+ {
+ return isEmpty() ? null : this.get(size() - 1);
+ }
+
+ /**
+ * Removes the first occurrence of the specified element from this deque. If
+ * the deque does not contain the element, it is unchanged. More formally,
+ * removes the first element e such that (o==null ? e==null : o.equals(e))
+ * (if such an element exists). Returns true if this deque contained the
+ * specified element (or equivalently, if this deque changed as a result of
+ * the call).
+ *
+ * @param o - element to be removed from this deque, if present
+ * @return true if an element was removed as a result of this call
+ * @throws ClassCastException - if the class of the specified element is
+ * incompatible with this deque
+ */
+ @Override
+ public boolean removeFirstOccurrence(Object o)
+ {
+ return isEmpty() ? false : this.remove(o);
+
+ }
+
+ /**
+ * Removes the last occurrence of the specified element from this deque. If
+ * the deque does not contain the element, it is unchanged. More formally,
+ * removes the last element e such that (o==null ? e==null : o.equals(e))
+ * (if such an element exists). Returns true if this deque contained the
+ * specified element (or equivalently, if this deque changed as a result of
+ * the call)
+ *
+ * @param o - element to be removed from this deque, if present
+ * @return true if an element was removed as a result of this call
+ * @throws ClassCastException - if the class of the specified element is
+ * incompatible with this deque (optional)
+ */
+ @Override
+ public boolean removeLastOccurrence(Object o)
+ {
+ Node temp = tail;
+ int index = size() - 1;
+ while (temp != null)
+ {
+ if (this.get(index).equals(o))
+ {
+ this.remove(index);
+ return true;
+ }
+ index--;
+ temp = temp.l;
+ }
+ return false;
+ }
+
+ /**
+ * Inserts the specified element into this queue if it is possible to do so
+ * immediately without violating capacity restrictions. When using a
+ * capacity-restricted queue, this method is generally preferable to add(E),
+ * which can fail to insert an element only by throwing an exception.
+ *
+ *
+ * @param e - the element to add
+ * @return true if the element was added to this queue, else false
+ * @throws: ClassCastException - if the class of the specified element
+ * prevents it from being added to this queue
+ */
+ @Override
+ public boolean offer(E e)
+ {
+ return this.offerLast(e);
+ }
+
+ /**
+ * Retrieves and removes the head of this queue. This method differs from
+ * poll only in that it throws an exception if this queue is empty.
+ *
+ * @return the head of this queue
+ * @throws NoSuchElementException - if this queue is empty
+ *
+ */
+ @Override
+ public E remove()
+ {
+ if (isEmpty())
+ {
+ throw new NoSuchElementException("The list is empty!");
+ }
+ return this.remove(0);
+ }
+
+ /**
+ * Retrieves and removes the head of this queue, or returns null if this
+ * queue is empty.
+ *
+ * @return the head of this queue, or null if this queue is empty
+ *
+ */
+ @Override
+ public E poll()
+ {
+ if (isEmpty())
+ {
+ throw new NoSuchElementException("The list is empty!");
+ }
+ return this.remove(0);
+ }
+
+ /**
+ * Retrieves, but does not remove, the head of this queue. This method
+ * differs from peek only in that it throws an exception if this queue is
+ * empty.
+ *
+ * @return the head of this queue
+ * @throws: NoSuchElementException - if this queue is empty
+ *
+ */
+ @Override
+ public E element()
+ {
+ if (isEmpty())
+ {
+ throw new NoSuchElementException("The list is empty!");
+ }
+ return this.get(0);
+ }
+
+ /**
+ * Retrieves, but does not remove, the head of this queue, or returns null
+ * if this queue is empty.
+ *
+ * @return the head of this queue, or null if this queue is empty
+ */
+ @Override
+ public E peek()
+ {
+ return isEmpty() ? null : this.get(0);
+ }
+
+ /**
+ * Pushes an element onto the stack represented by this list. In other
+ * words, inserts the element at the front of this list.
+ *
+ * This method is equivalent to addFirst(E). Specified by: push in interface
+ * Deque
+ *
+ * @param e - the element to push
+ */
+ @Override
+ public void push(E e)
+ {
+ this.addFirst(e);
+ }
+
+ /**
+ * Pops an element from the stack represented by this list. In other words,
+ * removes and returns the first element of this list.
+ *
+ * This method is equivalent to removeFirst(). Specified by: pop in
+ * interface Deque
+ *
+ * @return the element at the front of this list (which is the top of the
+ * stack represented by this list)
+ * @throws: NoSuchElementException - if this list is empty
+ */
+ @Override
+ public E pop()
+ {
+ if (isEmpty())
+ {
+ throw new NoSuchElementException("The list is empty!");
+ }
+ return this.remove(0);
+ }
+
+ /**
+ * Description copied from interface: Deque Returns an iterator over the
+ * elements in this deque in reverse sequential order. The elements will be
+ * returned in order from last (tail) to first (head).
+ *
+ * Specified by: descendingIterator in interface Deque
+ *
+ * @return an iterator over the elements in this deque in reverse sequence
+ */
+ @Override
+ public Iterator descendingIterator()
+ {
+
+ Iterator it = new Iterator()
+ {
+ Node trailPrevious = tail;
+
+ @Override
+ public boolean hasNext()
+ {
+ if (trailPrevious == null)
+ {
+ trailPrevious = tail;
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public E next()
+ {
+ Node temp = trailPrevious;
+ trailPrevious = trailPrevious.l;
+ return temp.e;
+ }
+ };
+ return it;
+ }
+
+ /**
+ * Returns a deep clone of the list.
+ *
+ * @return the cloned list
+ */
+ @Override
+ public Object clone()
+ {
+ ListASDV listCloned = new ListASDV();
+ Iterator it = this.iterator();
+ while (it.hasNext())
+ {
+
+ listCloned.add((E) it.next());
+ }
+ return listCloned;
+ }
+
+ @Override
+ public String toString()
+ {
+
+ String s = "ListASDV{ ";
+ Iterator it = iterator();
+ while (it.hasNext())
+ {
+ s += it.next() + " ";
+ }
+ s += '}';
+ return s;
+ }
+
+ public static void main(String[] args)
+ {
+ Map map = new HashMap();
+ map.put(1, "john");
+ map.put(2, "mary");
+ Set> set1 = map.entrySet();
+ }
+
+/*
+ public static void main(String[] args)
+ {
+ class ASDV_ENTRY implements Entry
+ {
+ T1 key;
+ T2 value;
+ public ASDV_ENTRY( T1 t1, T2 t2)
+ {
+ key = t1;
+ value = t2;
+ }
+ @Override
+ public T1 getKey()
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public T1 getValue()
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public T1 setValue(T1 value)
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+
+ }
+ Entry e1 = new ASDV_ENTRY("john", 20);
+
+ ListASDV listTest = new ListASDV();
+ listTest.add(e1);
+
+
+ ListASDV list = new ListASDV();
+ list.add(100);
+ list.addFirst(50);
+ list.add(1, 75);
+ list.addLast(200);
+ List collection = Arrays.asList(new Integer[]
+ {
+ 300, 400
+ });
+ list.addAll(collection);
+ try
+ {
+ list.addAll(8, collection);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ System.out.println(e.getMessage());
+ }
+
+ Iterator it = list.iterator();
+ System.out.println("\ntest add methods ***************************************");
+ while (it.hasNext())
+ {
+ Object o = it.next();
+ System.out.print(o + " ");
+ }
+
+ System.out.println("");
+ System.out.println("\nforEachRemaining(action) ***************************************");
+
+ Consumer action = new Consumer()
+ {
+ @Override
+ public void accept(Integer t)
+ {
+ System.out.print("*" + t + " ");
+ }
+
+ };
+ it = list.iterator();
+ it.next();
+ it.next();
+ it.forEachRemaining(action);
+ System.out.println("");
+ while (it.hasNext())
+ {
+ Object o = it.next();
+ System.out.print(o + " ");
+ }
+ System.out.println("");
+ it.forEachRemaining(action);
+
+ System.out.println("");
+ System.out.println("indexOf ***************************************");
+ System.out.println(list.indexOf(new A()));
+ System.out.println(list.indexOf(200));
+ System.out.println(list.indexOf(800));
+
+ System.out.println("\nclone() ***************************************");
+ ListASDV listCloned = (ListASDV) list.clone();
+ list.clear();
+ it = listCloned.iterator();
+ while (it.hasNext())
+ {
+ Object o = it.next();
+ System.out.print(o + " ");
+ }
+ System.out.println("\nsize of original list after clear: " + list.size());
+ list.addAll(0, listCloned);
+ System.out.println("\ntoString() ***************************************\n" + list);
+
+ System.out.println("\ncontains ***************************************");
+ System.out.println(list.contains(new A()));
+ System.out.println(list.contains(200));
+ System.out.println(list.contains(800));
+
+ System.out.println("\ncontainsAll ***************************************");
+ try
+ {
+ System.out.println(list.containsAll((Collection) new A()));
+ }
+ catch (ClassCastException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ System.out.println(list.containsAll(listCloned));
+ System.out.println(list.containsAll(Arrays.asList(new Integer[]
+ {
+ 100, 300
+ })));
+ System.out.println(list.containsAll(Arrays.asList(new Integer[]
+ {
+ 10, 300
+ })));
+
+ System.out.println("\ndiscendingIterator ***************************************");
+ Iterator descIt = list.descendingIterator();
+ while (descIt.hasNext())
+ {
+ Object o = descIt.next();
+ System.out.print(o + " ");
+ }
+
+ System.out.println("\nelement ***************************************");
+ System.out.println(list.element());
+ System.out.println(list.element());
+ listCloned.clear();
+ try
+ {
+ listCloned.element();
+ }
+ catch (NoSuchElementException e)
+ {
+ System.out.println(e.getMessage());
+ }
+
+ System.out.println("\nget(int) ***************************************");
+ System.out.println(list.get(0));
+ System.out.println(list.get(list.size() - 1));
+ try
+ {
+ list.get(list.size());
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ System.out.println(e.getMessage());
+ }
+
+ System.out.println("\ngetFirst() ***************************************");
+ System.out.println(list.getFirst());
+ System.out.println(list.getFirst());
+ try
+ {
+ listCloned.getFirst();
+ }
+ catch (NoSuchElementException e)
+ {
+ System.out.println(e.getMessage());
+ }
+
+ System.out.println("\n getLAst()***************************************");
+ System.out.println(list.getLast());
+ System.out.println(list.getLast());
+
+ try
+ {
+ listCloned.getLast();
+ }
+ catch (NoSuchElementException e)
+ {
+ System.out.println(e.getMessage());
+ }
+
+ System.out.println("\n isEmpty()***************************************");
+ System.out.println(list.isEmpty());
+ System.out.println(listCloned.isEmpty());
+
+ System.out.println("\n lastIndexOf***************************************");
+ list.add(1, -888);
+ list.add(4, -888);
+ System.out.println(list);
+ System.out.println(list.lastIndexOf(-888));
+ System.out.println(list.lastIndexOf(12));
+ System.out.println(list.lastIndexOf(new A()));
+
+ System.out.println("\nlistIterator( index=3) using next***************************************");
+ System.out.println(list);
+ ListIterator itList = list.listIterator(3);
+
+ while (itList.hasNext())
+ {
+ Object o = itList.next();
+ System.out.print("next Index " + itList.nextIndex());
+ System.out.print(" previous Index " + itList.previousIndex());
+ System.out.println(" node " + o + " ");
+ }
+
+ System.out.println("\nlistIterator( index=3) using previous ***************************************");
+ System.out.println(list);
+ itList = list.listIterator(3);
+
+ while (itList.hasPrevious())
+ {
+ Object o = itList.previous();
+ System.out.print("next Index " + itList.nextIndex());
+ System.out.print(" previous Index " + itList.previousIndex());
+ System.out.println(" node " + o + " ");
+ }
+
+ System.out.println("\nlistIterator with next ***************************************");
+ System.out.println(list);
+ itList = list.listIterator();
+
+ while (itList.hasNext())
+ {
+ Object o = itList.next();
+ System.out.print("next Index " + itList.nextIndex());
+ System.out.print(" previous Index " + itList.previousIndex());
+ System.out.println(" node " + o + " ");
+ }
+
+ System.out.println("\noffer methods ***************************************");
+ list.offer(500);
+ list.offerLast(600);
+ list.offerFirst(33);
+ System.out.println(list);
+
+ System.out.println("\npeek poll methods ***************************************");
+ System.out.println(list.peek());
+ System.out.println(list.peekFirst());
+ System.out.println(list.peekLast());
+ System.out.println(listCloned.peekLast());
+ System.out.println(list.poll());
+ System.out.println(list.pollFirst());
+ System.out.println(list.pollLast());
+ System.out.println(listCloned.pollFirst());
+
+ System.out.println("\npush pop methods ***************************************");
+ System.out.println(list);
+ Integer o = list.pop();
+ list.push(o);
+ System.out.println(list);
+ try
+ {
+ listCloned.pop();
+ }
+ catch (NoSuchElementException e)
+ {
+ System.out.println(e.getMessage());
+ }
+
+ System.out.println("\nremove methods ***************************************");
+ System.out.println(list);
+ System.out.println(list.removeLastOccurrence(-888));
+ System.out.println(list);
+ System.out.println(list.remove());
+ System.out.println(list.removeFirst());
+ System.out.println(list);
+ System.out.println(list.remove((Integer) 300));
+ try
+ {
+ list.remove(null);
+ }
+ catch (NullPointerException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ try
+ {
+ list.remove(200);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ System.out.println(list);
+
+ System.out.println("\nremoveAll( Collection c) ***************************************");
+ list.add(0, -888);
+ list.add(2, -888);
+ list.add(-888);
+ listCloned = (ListASDV) list.clone();
+ System.out.println(list);
+ List col = Arrays.asList(new Integer[]
+ {
+ -888, 200
+ });
+ list.removeAll(col);
+ System.out.println(list);
+
+ System.out.println("\nretailAll( Collection c) ***************************************");
+ list = (ListASDV) listCloned.clone();
+ list.retainAll(col);
+ System.out.println(list);
+
+ System.out.println("\nset ***************************************");
+ list.set(0, 100);
+ System.out.println(list);
+
+ System.out.println("\nsubList ***************************************");
+ List subList = list.subList(1, 3);
+ System.out.println(subList);
+ try
+ {
+ list.subList(1, 5);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ System.out.println(e.getMessage());
+ }
+
+ System.out.println("\ntoArray ***************************************");
+ System.out.println(list);
+ System.out.println(Arrays.asList(list.toArray()));
+
+ Integer[] ar = new Integer[list.size()];
+ System.out.println("\ntoArray(T[] ) ***************************************");
+ System.out.println(list);
+ System.out.println(Arrays.asList(list.toArray(ar)));
+
+ ar = new Integer[1];
+ System.out.println(Arrays.asList(list.toArray(ar)));
+
+ ar = new Integer[list.size() + list.size()];
+ System.out.println(Arrays.asList(list.toArray(ar)));
+
+ ar = null;
+ try
+ {
+ list.toArray(ar);
+ }
+ catch (NullPointerException e)
+ {
+ System.out.println(e.getMessage());
+ }
+
+ }
+*/
+}
+
+
+class A
+{
+}
+
diff --git a/Semester 4/Assignments/ProjectTrees_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/projecttrees_calebfontenot/TreeASDV.java b/Semester 4/Assignments/ProjectTrees_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/projecttrees_calebfontenot/TreeASDV.java
index f79934f..f84692b 100644
--- a/Semester 4/Assignments/ProjectTrees_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/projecttrees_calebfontenot/TreeASDV.java
+++ b/Semester 4/Assignments/ProjectTrees_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/projecttrees_calebfontenot/TreeASDV.java
@@ -4,6 +4,8 @@
*/
package edu.slcc.asdv.caleb.projecttrees_calebfontenot;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Queue;
@@ -12,8 +14,9 @@ import java.util.Stack;
/**
*
* @author caleb
+ * @param
*/
-public class TreeASDV {
+public class TreeASDV implements Cloneable {
private Node root;
@@ -24,7 +27,21 @@ public class TreeASDV {
Node rightChild;
}
- public boolean insert(T t) {
+ @Override
+ public Object clone()
+ {
+ System.out.println("Cloning...");
+ TreeASDV clone = new TreeASDV();
+ ArrayList oldData = this.getBreadthFirstArray();
+ for (int i = 0; i < oldData.size(); ++i) {
+ //System.out.println(oldData.get(i));
+ clone.insert(oldData.get(i));
+ }
+ return clone;
+ }
+
+ public boolean insert(T t)
+ {
Node newNode = new Node<>();
newNode.data = t;
@@ -55,7 +72,8 @@ public class TreeASDV {
return true;
}
- private void inOrder(Node p) {
+ private void inOrder(Node p)
+ {
if (p == null) {
return;
}
@@ -65,11 +83,8 @@ public class TreeASDV {
inOrder(p.rightChild);
}
- public void inOrder() {
- inOrder(this.root);
- }
-
- public Node findNode(T t) {
+ public Node findNode(T t)
+ {
Node currentNode = root;
while (currentNode != null) {
if (t.compareTo(currentNode.data) == 0) {
@@ -82,8 +97,9 @@ public class TreeASDV {
}
return null;
}
-
- public boolean remove(T t) {
+
+ public boolean remove(T t)
+ {
// Initialize parent and current nodes for traversal
Node parent = null;
Node current = root;
@@ -134,7 +150,8 @@ public class TreeASDV {
}
// Helper method to find in-order successor of a node
- private Node getSuccessor(Node node) {
+ private Node getSuccessor(Node node)
+ {
Node current = node.rightChild;
Node successorParent = node;
Node successor = node;
@@ -156,12 +173,80 @@ public class TreeASDV {
return successor;
}
- public ListIterator listIterator() {
- //ListIterator it = new ListIterator();
- return null;
+ // Inorder ListIterator
+ public Iterator listIterator()
+ {
+ return new InorderIterator();
}
- public void breadthFirstTraversal() {
+ private class InorderIterator implements Iterator {
+
+ private Stack> stack;
+
+ public InorderIterator()
+ {
+ stack = new Stack<>();
+ pushLeft(root);
+ }
+
+ private void pushLeft(Node node)
+ {
+ while (node != null) {
+ stack.push(node);
+ node = node.leftChild;
+ }
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return !stack.isEmpty();
+ }
+
+ @Override
+ public T next()
+ {
+ if (!hasNext()) {
+ throw new java.util.NoSuchElementException();
+ }
+ Node current = stack.pop();
+ pushLeft(current.rightChild);
+ return current.data;
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public ArrayList getBreadthFirstArray()
+ {
+ ArrayList returnArray = new ArrayList();
+ if (root == null) {
+ return returnArray;
+ }
+ Queue> queue = new LinkedList<>();
+
+ queue.offer(root);
+
+ while (!queue.isEmpty()) {
+ Node current = queue.poll();
+ returnArray.add(current.data);
+
+ if (current.leftChild != null) {
+ queue.offer(current.leftChild);
+ }
+ if (current.rightChild != null) {
+ queue.offer(current.rightChild);
+ }
+ }
+ return returnArray;
+ }
+
+ public void breadthFirstTraversal()
+ {
if (root == null) {
return;
}
@@ -182,12 +267,18 @@ public class TreeASDV {
}
}
+ @Override
+ public boolean equals(Object obj) {
+ return this.getBreadthFirstArray().equals(((TreeASDV) obj).getBreadthFirstArray());
+ }
- public int height() {
+ public int height()
+ {
return calculateHeight(root);
}
- private int calculateHeight(Node node) {
+ private int calculateHeight(Node node)
+ {
if (node == null) {
return 0;
}
@@ -197,21 +288,24 @@ public class TreeASDV {
return 1 + Math.max(leftHeight, rightHeight);
}
-
- public boolean isFullBST() {
+
+ public boolean isFullBST()
+ {
int height = height();
int nodeCount = countNodes(root);
return nodeCount == (1 << height) - 1; // Formula for full binary tree
}
- private int countNodes(Node node) {
+ private int countNodes(Node node)
+ {
if (node == null) {
return 0;
}
return 1 + countNodes(node.leftChild) + countNodes(node.rightChild);
}
-
- public void inorder() {
+
+ public void inOrder()
+ {
if (root == null) {
return;
}
@@ -230,7 +324,8 @@ public class TreeASDV {
}
}
- public static void main(String[] args) {
+ public static void main(String[] args) throws CloneNotSupportedException
+ {
TreeASDV tree = new TreeASDV<>();
// Insert some elements into the tree
tree.insert(5);
@@ -254,7 +349,16 @@ public class TreeASDV {
// Test inorder traversal without recursion
System.out.println("Inorder Traversal without Recursion:");
- tree.inorder();
+ tree.inOrder();
System.out.println();
+ System.out.println("array list from breadth traversal");
+ System.out.println(tree.getBreadthFirstArray());
+ System.out.println("Cloned Tree:");
+ TreeASDV clonedTree = (TreeASDV) tree.clone();
+ clonedTree.breadthFirstTraversal();
+ System.out.println();
+ System.out.println("Does the original tree and the clone tree equal? " + (tree.equals(clonedTree) ? "yes" : "no") );
+ tree.insert(3000000);
+ System.out.println("Does the original tree and the clone tree equal? " + (tree.equals(clonedTree) ? "yes" : "no") );
}
}