honey, its time for you to learn something else in java! \n yes honey... :depressed:
This commit is contained in:
parent
3047558ef6
commit
ad38d64219
3
.gitignore
vendored
3
.gitignore
vendored
@ -200,3 +200,6 @@
|
|||||||
/Semester 4/Assignments/DataStructures/target/
|
/Semester 4/Assignments/DataStructures/target/
|
||||||
/MergeSort/target/
|
/MergeSort/target/
|
||||||
/Semester 3/Exams/ProgrammingExam2_CalebFontenot/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/
|
||||||
|
14
Semester 4/Assignments/HashMapASDV/pom.xml
Normal file
14
Semester 4/Assignments/HashMapASDV/pom.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>edu.slcc.asdv.caleb</groupId>
|
||||||
|
<artifactId>HashMapASDV</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>20</maven.compiler.source>
|
||||||
|
<maven.compiler.target>20</maven.compiler.target>
|
||||||
|
<exec.mainClass>edu.slcc.asdv.caleb.hashmapasdv.HashMapASDV</exec.mainClass>
|
||||||
|
</properties>
|
||||||
|
</project>
|
@ -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!");
|
||||||
|
}
|
||||||
|
}
|
BIN
Semester 4/Assignments/HashMapASDV_Ant/ListASDV.jar
Normal file
BIN
Semester 4/Assignments/HashMapASDV_Ant/ListASDV.jar
Normal file
Binary file not shown.
73
Semester 4/Assignments/HashMapASDV_Ant/build.xml
Normal file
73
Semester 4/Assignments/HashMapASDV_Ant/build.xml
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- You may freely edit this file. See commented blocks below for -->
|
||||||
|
<!-- some examples of how to customize the build. -->
|
||||||
|
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||||
|
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||||
|
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||||
|
<!-- the Compile on Save feature is turned off for the project. -->
|
||||||
|
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||||
|
<!-- in the project's Project Properties dialog box.-->
|
||||||
|
<project name="HashMapASDV_Ant" default="default" basedir=".">
|
||||||
|
<description>Builds, tests, and runs the project HashMapASDV_Ant.</description>
|
||||||
|
<import file="nbproject/build-impl.xml"/>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
There exist several targets which are by default empty and which can be
|
||||||
|
used for execution of your tasks. These targets are usually executed
|
||||||
|
before and after some main targets. They are:
|
||||||
|
|
||||||
|
-pre-init: called before initialization of project properties
|
||||||
|
-post-init: called after initialization of project properties
|
||||||
|
-pre-compile: called before javac compilation
|
||||||
|
-post-compile: called after javac compilation
|
||||||
|
-pre-compile-single: called before javac compilation of single file
|
||||||
|
-post-compile-single: called after javac compilation of single file
|
||||||
|
-pre-compile-test: called before javac compilation of JUnit tests
|
||||||
|
-post-compile-test: called after javac compilation of JUnit tests
|
||||||
|
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||||
|
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||||
|
-pre-jar: called before JAR building
|
||||||
|
-post-jar: called after JAR building
|
||||||
|
-post-clean: called after cleaning build products
|
||||||
|
|
||||||
|
(Targets beginning with '-' are not intended to be called on their own.)
|
||||||
|
|
||||||
|
Example of inserting an obfuscator after compilation could look like this:
|
||||||
|
|
||||||
|
<target name="-post-compile">
|
||||||
|
<obfuscate>
|
||||||
|
<fileset dir="${build.classes.dir}"/>
|
||||||
|
</obfuscate>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
For list of available properties check the imported
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
|
||||||
|
Another way to customize the build is by overriding existing main targets.
|
||||||
|
The targets of interest are:
|
||||||
|
|
||||||
|
-init-macrodef-javac: defines macro for javac compilation
|
||||||
|
-init-macrodef-junit: defines macro for junit execution
|
||||||
|
-init-macrodef-debug: defines macro for class debugging
|
||||||
|
-init-macrodef-java: defines macro for class execution
|
||||||
|
-do-jar: JAR building
|
||||||
|
run: execution of project
|
||||||
|
-javadoc-build: Javadoc generation
|
||||||
|
test-report: JUnit report generation
|
||||||
|
|
||||||
|
An example of overriding the target for project execution could look like this:
|
||||||
|
|
||||||
|
<target name="run" depends="HashMapASDV_Ant-impl.jar">
|
||||||
|
<exec dir="bin" executable="launcher.exe">
|
||||||
|
<arg file="${dist.jar}"/>
|
||||||
|
</exec>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
Notice that the overridden target depends on the jar target and not only on
|
||||||
|
the compile target as the regular run target does. Again, for a list of available
|
||||||
|
properties which you can use, check the target you are overriding in the
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
-->
|
||||||
|
</project>
|
3
Semester 4/Assignments/HashMapASDV_Ant/manifest.mf
Normal file
3
Semester 4/Assignments/HashMapASDV_Ant/manifest.mf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
X-COMMENT: Main-Class will be added automatically by build
|
||||||
|
|
1771
Semester 4/Assignments/HashMapASDV_Ant/nbproject/build-impl.xml
Normal file
1771
Semester 4/Assignments/HashMapASDV_Ant/nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -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
|
@ -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
|
15
Semester 4/Assignments/HashMapASDV_Ant/nbproject/project.xml
Normal file
15
Semester 4/Assignments/HashMapASDV_Ant/nbproject/project.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||||
|
<type>org.netbeans.modules.java.j2seproject</type>
|
||||||
|
<configuration>
|
||||||
|
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||||
|
<name>HashMapASDV_Ant</name>
|
||||||
|
<source-roots>
|
||||||
|
<root id="src.dir"/>
|
||||||
|
</source-roots>
|
||||||
|
<test-roots>
|
||||||
|
<root id="test.src.dir"/>
|
||||||
|
</test-roots>
|
||||||
|
</data>
|
||||||
|
</configuration>
|
||||||
|
</project>
|
@ -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<K, V> implements Entry<K, V>, Comparable<K>
|
||||||
|
{
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
package edu.slcc.asdv.caleb.projecttrees_calebfontenot;
|
package edu.slcc.asdv.caleb.projecttrees_calebfontenot;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@ -12,8 +14,9 @@ import java.util.Stack;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author caleb
|
* @author caleb
|
||||||
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public class TreeASDV<T extends Comparable> {
|
public class TreeASDV<T extends Comparable> implements Cloneable {
|
||||||
|
|
||||||
private Node<T> root;
|
private Node<T> root;
|
||||||
|
|
||||||
@ -24,7 +27,21 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
Node<T> rightChild;
|
Node<T> rightChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean insert(T t) {
|
@Override
|
||||||
|
public Object clone()
|
||||||
|
{
|
||||||
|
System.out.println("Cloning...");
|
||||||
|
TreeASDV<T> clone = new TreeASDV<T>();
|
||||||
|
ArrayList<T> 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<T> newNode = new Node<>();
|
Node<T> newNode = new Node<>();
|
||||||
newNode.data = t;
|
newNode.data = t;
|
||||||
|
|
||||||
@ -55,7 +72,8 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void inOrder(Node<T> p) {
|
private void inOrder(Node<T> p)
|
||||||
|
{
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -65,11 +83,8 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
inOrder(p.rightChild);
|
inOrder(p.rightChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inOrder() {
|
public Node<T> findNode(T t)
|
||||||
inOrder(this.root);
|
{
|
||||||
}
|
|
||||||
|
|
||||||
public Node<T> findNode(T t) {
|
|
||||||
Node<T> currentNode = root;
|
Node<T> currentNode = root;
|
||||||
while (currentNode != null) {
|
while (currentNode != null) {
|
||||||
if (t.compareTo(currentNode.data) == 0) {
|
if (t.compareTo(currentNode.data) == 0) {
|
||||||
@ -83,7 +98,8 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean remove(T t) {
|
public boolean remove(T t)
|
||||||
|
{
|
||||||
// Initialize parent and current nodes for traversal
|
// Initialize parent and current nodes for traversal
|
||||||
Node<T> parent = null;
|
Node<T> parent = null;
|
||||||
Node<T> current = root;
|
Node<T> current = root;
|
||||||
@ -134,7 +150,8 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to find in-order successor of a node
|
// Helper method to find in-order successor of a node
|
||||||
private Node<T> getSuccessor(Node<T> node) {
|
private Node<T> getSuccessor(Node<T> node)
|
||||||
|
{
|
||||||
Node<T> current = node.rightChild;
|
Node<T> current = node.rightChild;
|
||||||
Node<T> successorParent = node;
|
Node<T> successorParent = node;
|
||||||
Node<T> successor = node;
|
Node<T> successor = node;
|
||||||
@ -156,12 +173,80 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
return successor;
|
return successor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListIterator<T> listIterator() {
|
// Inorder ListIterator
|
||||||
//ListIterator it = new ListIterator<T>();
|
public Iterator<T> listIterator()
|
||||||
return null;
|
{
|
||||||
|
return new InorderIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void breadthFirstTraversal() {
|
private class InorderIterator implements Iterator<T> {
|
||||||
|
|
||||||
|
private Stack<Node<T>> stack;
|
||||||
|
|
||||||
|
public InorderIterator()
|
||||||
|
{
|
||||||
|
stack = new Stack<>();
|
||||||
|
pushLeft(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pushLeft(Node<T> 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<T> current = stack.pop();
|
||||||
|
pushLeft(current.rightChild);
|
||||||
|
return current.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<T> getBreadthFirstArray()
|
||||||
|
{
|
||||||
|
ArrayList<T> returnArray = new ArrayList<T>();
|
||||||
|
if (root == null) {
|
||||||
|
return returnArray;
|
||||||
|
}
|
||||||
|
Queue<Node<T>> queue = new LinkedList<>();
|
||||||
|
|
||||||
|
queue.offer(root);
|
||||||
|
|
||||||
|
while (!queue.isEmpty()) {
|
||||||
|
Node<T> 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) {
|
if (root == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -182,12 +267,18 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return this.getBreadthFirstArray().equals(((TreeASDV) obj).getBreadthFirstArray());
|
||||||
|
}
|
||||||
|
|
||||||
public int height() {
|
public int height()
|
||||||
|
{
|
||||||
return calculateHeight(root);
|
return calculateHeight(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculateHeight(Node<T> node) {
|
private int calculateHeight(Node<T> node)
|
||||||
|
{
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -198,20 +289,23 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
return 1 + Math.max(leftHeight, rightHeight);
|
return 1 + Math.max(leftHeight, rightHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFullBST() {
|
public boolean isFullBST()
|
||||||
|
{
|
||||||
int height = height();
|
int height = height();
|
||||||
int nodeCount = countNodes(root);
|
int nodeCount = countNodes(root);
|
||||||
return nodeCount == (1 << height) - 1; // Formula for full binary tree
|
return nodeCount == (1 << height) - 1; // Formula for full binary tree
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countNodes(Node<T> node) {
|
private int countNodes(Node<T> node)
|
||||||
|
{
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1 + countNodes(node.leftChild) + countNodes(node.rightChild);
|
return 1 + countNodes(node.leftChild) + countNodes(node.rightChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inorder() {
|
public void inOrder()
|
||||||
|
{
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -230,7 +324,8 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws CloneNotSupportedException
|
||||||
|
{
|
||||||
TreeASDV<Integer> tree = new TreeASDV<>();
|
TreeASDV<Integer> tree = new TreeASDV<>();
|
||||||
// Insert some elements into the tree
|
// Insert some elements into the tree
|
||||||
tree.insert(5);
|
tree.insert(5);
|
||||||
@ -254,7 +349,16 @@ public class TreeASDV<T extends Comparable> {
|
|||||||
|
|
||||||
// Test inorder traversal without recursion
|
// Test inorder traversal without recursion
|
||||||
System.out.println("Inorder Traversal without Recursion:");
|
System.out.println("Inorder Traversal without Recursion:");
|
||||||
tree.inorder();
|
tree.inOrder();
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
System.out.println("array list from breadth traversal");
|
||||||
|
System.out.println(tree.getBreadthFirstArray());
|
||||||
|
System.out.println("Cloned Tree:");
|
||||||
|
TreeASDV<Integer> clonedTree = (TreeASDV<Integer>) 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") );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user