From aba263932067d6b3178adc71f019cb1fd4a61c7e Mon Sep 17 00:00:00 2001 From: phuuthanh2003 Date: Thu, 15 Feb 2024 20:13:16 +0700 Subject: [PATCH 1/2] seach, insert, traveral binary sub tree in java --- BinarySubTree_Java/build.xml | 73 + BinarySubTree_Java/manifest.mf | 3 + BinarySubTree_Java/nbproject/build-impl.xml | 1445 +++++++++++++++++ .../nbproject/genfiles.properties | 8 + .../nbproject/private/config.properties | 0 .../nbproject/private/private.properties | 6 + .../nbproject/private/private.xml | 11 + .../nbproject/project.properties | 76 + BinarySubTree_Java/nbproject/project.xml | 18 + BinarySubTree_Java/src/bstree/Main.java | 202 +++ .../src/deletionbycopying/Main.java | 164 ++ .../src/deletionbymerging/Main.java | 213 +++ 12 files changed, 2219 insertions(+) create mode 100644 BinarySubTree_Java/build.xml create mode 100644 BinarySubTree_Java/manifest.mf create mode 100644 BinarySubTree_Java/nbproject/build-impl.xml create mode 100644 BinarySubTree_Java/nbproject/genfiles.properties create mode 100644 BinarySubTree_Java/nbproject/private/config.properties create mode 100644 BinarySubTree_Java/nbproject/private/private.properties create mode 100644 BinarySubTree_Java/nbproject/private/private.xml create mode 100644 BinarySubTree_Java/nbproject/project.properties create mode 100644 BinarySubTree_Java/nbproject/project.xml create mode 100644 BinarySubTree_Java/src/bstree/Main.java create mode 100644 BinarySubTree_Java/src/deletionbycopying/Main.java create mode 100644 BinarySubTree_Java/src/deletionbymerging/Main.java diff --git a/BinarySubTree_Java/build.xml b/BinarySubTree_Java/build.xml new file mode 100644 index 00000000..5208649d --- /dev/null +++ b/BinarySubTree_Java/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project BSTree. + + + diff --git a/BinarySubTree_Java/manifest.mf b/BinarySubTree_Java/manifest.mf new file mode 100644 index 00000000..328e8e5b --- /dev/null +++ b/BinarySubTree_Java/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/BinarySubTree_Java/nbproject/build-impl.xml b/BinarySubTree_Java/nbproject/build-impl.xml new file mode 100644 index 00000000..3dbd26b8 --- /dev/null +++ b/BinarySubTree_Java/nbproject/build-impl.xml @@ -0,0 +1,1445 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BinarySubTree_Java/nbproject/genfiles.properties b/BinarySubTree_Java/nbproject/genfiles.properties new file mode 100644 index 00000000..1a52ff3e --- /dev/null +++ b/BinarySubTree_Java/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0cb89e3a +build.xml.script.CRC32=e1abe2f4 +build.xml.stylesheet.CRC32=8064a381@1.80.1.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=0cb89e3a +nbproject/build-impl.xml.script.CRC32=c56d7b74 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/BinarySubTree_Java/nbproject/private/config.properties b/BinarySubTree_Java/nbproject/private/config.properties new file mode 100644 index 00000000..e69de29b diff --git a/BinarySubTree_Java/nbproject/private/private.properties b/BinarySubTree_Java/nbproject/private/private.properties new file mode 100644 index 00000000..5e011a26 --- /dev/null +++ b/BinarySubTree_Java/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Admin\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/BinarySubTree_Java/nbproject/private/private.xml b/BinarySubTree_Java/nbproject/private/private.xml new file mode 100644 index 00000000..b698a1ad --- /dev/null +++ b/BinarySubTree_Java/nbproject/private/private.xml @@ -0,0 +1,11 @@ + + + + + + file:/D:/FPTU/Ki3/CSD201/BSTree/src/deletionbycopying/Main.java + file:/D:/FPTU/Ki3/CSD201/BSTree/src/bstree/Main.java + file:/D:/FPTU/Ki3/CSD201/BSTree/src/deletionbymerging/Main.java + + + diff --git a/BinarySubTree_Java/nbproject/project.properties b/BinarySubTree_Java/nbproject/project.properties new file mode 100644 index 00000000..0c45575b --- /dev/null +++ b/BinarySubTree_Java/nbproject/project.properties @@ -0,0 +1,76 @@ +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=BSTree +application.vendor=Admin +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.test.classpath=\ + ${run.test.classpath} +# 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}/BSTree.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=bstree.Main +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} +# 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.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/BinarySubTree_Java/nbproject/project.xml b/BinarySubTree_Java/nbproject/project.xml new file mode 100644 index 00000000..eb64d67f --- /dev/null +++ b/BinarySubTree_Java/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + BSTree + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/BinarySubTree_Java/src/bstree/Main.java b/BinarySubTree_Java/src/bstree/Main.java new file mode 100644 index 00000000..21aa9a6f --- /dev/null +++ b/BinarySubTree_Java/src/bstree/Main.java @@ -0,0 +1,202 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package bstree; + +import java.util.LinkedList; + +class Node { + + int info; + Node left, right; + + Node(int x) { + info = x; + left = right = null; + } +} + +class MyQueue { + + LinkedList a; + + MyQueue() { + a = new LinkedList(); + } + + boolean isEmpty() { + return (a.isEmpty()); + } + + void enqueue(Object x) { + a.add(x); + } + + Object dequeue() { + return (a.removeFirst()); + } +} + +class BTree { + + Node root; + + BTree() { + root = null; + } + + boolean isEmpty() { + return (root == null); + } + + Node search(Node p, int x) { + if (p == null) { + return (null); + } + if (p.info == x) { + return (p); + } + if (x < p.info) { + return (search(p.left, x)); + } else { + return (search(p.right, x)); + } + } + + void insert(int x) { + Node q = new Node(x); + if (isEmpty()) { + root = q; + return; + } + Node f, p; + f = null; + p = root; + while (p != null) { + if (p.info == x) { + System.out.println("The key " + x + + " already exists, no insertion"); + return; + } + f = p; + if (x < p.info) { + p = p.left; + } else { + p = p.right; + } + } + if (x < f.info) { + f.left = q; + } else { + f.right = q; + } + } + + void insertMany(int[] a) { + for (int i = 0; i < a.length; i++) { + insert(a[i]); + } + } + + void visit(Node p) { + System.out.print(p.info + " "); + } + + void preOrder(Node p) { + if (p == null) { + return; + } + visit(p); + preOrder(p.left); + preOrder(p.right); + } + + void inOrder(Node p) { + if (p == null) { + return; + } + inOrder(p.left); + visit(p); + inOrder(p.right); + } + + void postOrder(Node p) { + if (p == null) { + return; + } + postOrder(p.left); + postOrder(p.right); + visit(p); + } + + void breadth() { + if (root == null) { + return; + } + MyQueue q = new MyQueue(); + q.enqueue(root); + Node p; + while (!q.isEmpty()) { + p = (Node) q.dequeue(); + if (p.left != null) { + q.enqueue(p.left); + } + if (p.right != null) { + q.enqueue(p.right); + } + visit(p); + } + } + + Node deleteLeaves(Node root, int x) { + if (root == null) { + return null; + } + root.left = deleteLeaves(root.left, x); + root.right = deleteLeaves(root.right, x); + if (root.info == x && root.left == null && root.right == null) { + return null; + } + return root; + } +} + +public class Main { + + public static void main(String[] args) { + BTree t = new BTree(); + int[] a = {11, 5, 9, 7, 13}; + t.insertMany(a); + + /* 11 - Pre-order traverse 11 5 9 7 13 + / \ - In-order traverse 5 7 9 11 13 + 5 13 - Post-order traverse 7 9 5 13 11 + \ - Level-order traverse 11 5 13 9 7 + 9 (Breadth-first) + / + 7 + */ + System.out.print("BST after insertion (11 5 9 7 13):"); + System.out.print("\n - Pre-order traverse "); + t.preOrder(t.root); + System.out.print("\n - In-order traverse "); + t.inOrder(t.root); + System.out.print("\n - Post-order traverse "); + t.postOrder(t.root); + System.out.print("\n - Breadth-first traverse "); + t.breadth(); + System.out.print("\nBST after deletion 7:"); + t.deleteLeaves(t.root, 7); + System.out.print("\n - Pre-order traverse "); + t.preOrder(t.root); + System.out.print("\n - In-order traverse "); + t.inOrder(t.root); + System.out.print("\n - Post-order traverse "); + t.postOrder(t.root); + System.out.print("\n - Breadth-first traverse "); + t.breadth(); + System.out.println(); + } +} diff --git a/BinarySubTree_Java/src/deletionbycopying/Main.java b/BinarySubTree_Java/src/deletionbycopying/Main.java new file mode 100644 index 00000000..c39b5089 --- /dev/null +++ b/BinarySubTree_Java/src/deletionbycopying/Main.java @@ -0,0 +1,164 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package deletionbycopying; +class Node { + int info; + Node left,right; + Node(int x) {info=x;left=right=null;} +} + +class BSTree { + Node root; + BSTree() {root=null;} + boolean isEmpty() {return(root==null);} + + void insert(int x) { + if(root==null) {root = new Node(x); return;} + Node f=null, p=root; + while(p!=null) { + if(p.info==x) { + System.out.println(" The key " + x + + " already exists, no insertion."); + return; + } + if(x key) { + return search(p.left, key); + } else { + return search(p.right, key); + } + } + + public void deleteByMerging(int x) { + Node p = search(root, x); + if (p == null) { + System.out.println("Key " + x + " does not exists, deletion failed"); + return; + } + //find f is father of p + Node f = null, q = root; + while (q != p) { + f = q; + if (q.info > p.info) { + q = q.left; + } else { + q = q.right; + } + } + //1- p has no child + if (p.left == null && p.right == null) { + if (f == null) { + root = null; + } else if (f.left == p) { + f.left = null; + } else { + f.right = null; + } + } //2- p has the left child only + else if (p.left != null && p.right == null) { + if (f == null) { + root = p.left; + } else if (f.left == p) { + f.left = p.left; + } else { + f.right = p.left; + } + } //3- p has the right child only + else if (p.left == null && p.right != null) { + if (f == null) { + root = p.right; + } else if (f.left == p) { + f.left = p.right; + } else { + f.right = p.right; + } + } //4- p has both left and right children + else if (p.left != null && p.right != null) { + //find q is the largest node on the left child of p (q is the right + //child with the largest key of the left child of p) + q = p.left; + Node t = null; + while (q.right != null) { + t = q; + q = q.right; + } + //merge the right child of p into q + Node rp = p.right; + q.right = rp; + if (f == null) { + root = p.left; + } else if (f.left == p) { + f.left = p.left; + } else { + f.right = p.left; + } + } + } + + void visit(Node p) { + if (p == null) { + return; + } + System.out.print(" " + p.info); + } + + void preOrder(Node p) { + if (p == null) { + return; + } + visit(p); + preOrder(p.left); + preOrder(p.right); + } + + void inOrder(Node p) { + if (p == null) { + return; + } + inOrder(p.left); + visit(p); + inOrder(p.right); + } + + void postOrder(Node p) { + if (p == null) { + return; + } + postOrder(p.left); + postOrder(p.right); + visit(p); + } + + void addArray(int[] a) { + for (int i = 0; i < a.length; i++) { + insert(a[i]); + } + } +} + +public class Main { + + public static void main(String[] args) { + BSTree t = new BSTree(); + System.out.println(" BST after insertion (3 5 1 5 9 8 2):"); + int[] a = {3, 5, 1, 5, 9, 8, 2}; + t.addArray(a); + + /* 3 1 + / \ \ + 1 5 2 + \ \ \ + 2 9 5 + / \ + 8 9 + - Pre-order : 3 1 2 5 9 8 / - Pre-order : 1 2 5 9 8 + - In-order : 1 2 3 5 8 9 8 - In-order : 1 2 5 8 9 + - Post-order: 2 1 8 9 5 3 - Post-order: 8 9 5 2 1 + */ + System.out.print(" - Pre-order traverse:"); + t.preOrder(t.root); + System.out.print("\n - In-order traverse:"); + t.inOrder(t.root); + System.out.print("\n - Post-order traverse: "); + t.postOrder(t.root); + System.out.print("\n Ater deleting 3:"); + t.deleteByMerging(3); + System.out.print("\n - Pre-order traverse:"); + t.preOrder(t.root); + System.out.print("\n - In-order traverse:"); + t.inOrder(t.root); + System.out.print("\n - Post-order traverse: "); + t.postOrder(t.root); + System.out.println(); + } +} From 8439e23ab64ccd4a73240db7b8bd3498d84073fc Mon Sep 17 00:00:00 2001 From: phuuthanh2003 Date: Thu, 15 Feb 2024 20:24:24 +0700 Subject: [PATCH 2/2] delete in bst --- BinarySubTree_Java/build.xml | 73 - BinarySubTree_Java/manifest.mf | 3 - BinarySubTree_Java/nbproject/build-impl.xml | 1445 ----------------- .../nbproject/genfiles.properties | 8 - .../nbproject/private/config.properties | 0 .../nbproject/private/private.properties | 6 - .../nbproject/private/private.xml | 11 - .../nbproject/project.properties | 76 - BinarySubTree_Java/nbproject/project.xml | 18 - BinarySubTree_Java/src/bstree/Main.java | 202 --- .../Deletebymerging.java | 0 .../deletebycopying.java | 0 12 files changed, 1842 deletions(-) delete mode 100644 BinarySubTree_Java/build.xml delete mode 100644 BinarySubTree_Java/manifest.mf delete mode 100644 BinarySubTree_Java/nbproject/build-impl.xml delete mode 100644 BinarySubTree_Java/nbproject/genfiles.properties delete mode 100644 BinarySubTree_Java/nbproject/private/config.properties delete mode 100644 BinarySubTree_Java/nbproject/private/private.properties delete mode 100644 BinarySubTree_Java/nbproject/private/private.xml delete mode 100644 BinarySubTree_Java/nbproject/project.properties delete mode 100644 BinarySubTree_Java/nbproject/project.xml delete mode 100644 BinarySubTree_Java/src/bstree/Main.java rename BinarySubTree_Java/src/deletionbymerging/Main.java => Deletion In BST/Deletebymerging.java (100%) rename BinarySubTree_Java/src/deletionbycopying/Main.java => Deletion In BST/deletebycopying.java (100%) diff --git a/BinarySubTree_Java/build.xml b/BinarySubTree_Java/build.xml deleted file mode 100644 index 5208649d..00000000 --- a/BinarySubTree_Java/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project BSTree. - - - diff --git a/BinarySubTree_Java/manifest.mf b/BinarySubTree_Java/manifest.mf deleted file mode 100644 index 328e8e5b..00000000 --- a/BinarySubTree_Java/manifest.mf +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -X-COMMENT: Main-Class will be added automatically by build - diff --git a/BinarySubTree_Java/nbproject/build-impl.xml b/BinarySubTree_Java/nbproject/build-impl.xml deleted file mode 100644 index 3dbd26b8..00000000 --- a/BinarySubTree_Java/nbproject/build-impl.xml +++ /dev/null @@ -1,1445 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/BinarySubTree_Java/nbproject/genfiles.properties b/BinarySubTree_Java/nbproject/genfiles.properties deleted file mode 100644 index 1a52ff3e..00000000 --- a/BinarySubTree_Java/nbproject/genfiles.properties +++ /dev/null @@ -1,8 +0,0 @@ -build.xml.data.CRC32=0cb89e3a -build.xml.script.CRC32=e1abe2f4 -build.xml.stylesheet.CRC32=8064a381@1.80.1.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=0cb89e3a -nbproject/build-impl.xml.script.CRC32=c56d7b74 -nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/BinarySubTree_Java/nbproject/private/config.properties b/BinarySubTree_Java/nbproject/private/config.properties deleted file mode 100644 index e69de29b..00000000 diff --git a/BinarySubTree_Java/nbproject/private/private.properties b/BinarySubTree_Java/nbproject/private/private.properties deleted file mode 100644 index 5e011a26..00000000 --- a/BinarySubTree_Java/nbproject/private/private.properties +++ /dev/null @@ -1,6 +0,0 @@ -compile.on.save=true -do.depend=false -do.jar=true -javac.debug=true -javadoc.preview=true -user.properties.file=C:\\Users\\Admin\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/BinarySubTree_Java/nbproject/private/private.xml b/BinarySubTree_Java/nbproject/private/private.xml deleted file mode 100644 index b698a1ad..00000000 --- a/BinarySubTree_Java/nbproject/private/private.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - file:/D:/FPTU/Ki3/CSD201/BSTree/src/deletionbycopying/Main.java - file:/D:/FPTU/Ki3/CSD201/BSTree/src/bstree/Main.java - file:/D:/FPTU/Ki3/CSD201/BSTree/src/deletionbymerging/Main.java - - - diff --git a/BinarySubTree_Java/nbproject/project.properties b/BinarySubTree_Java/nbproject/project.properties deleted file mode 100644 index 0c45575b..00000000 --- a/BinarySubTree_Java/nbproject/project.properties +++ /dev/null @@ -1,76 +0,0 @@ -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=BSTree -application.vendor=Admin -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.test.classpath=\ - ${run.test.classpath} -# 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}/BSTree.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.external.vm=true -javac.processorpath=\ - ${javac.classpath} -javac.source=1.8 -javac.target=1.8 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -main.class=bstree.Main -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} -# 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.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test diff --git a/BinarySubTree_Java/nbproject/project.xml b/BinarySubTree_Java/nbproject/project.xml deleted file mode 100644 index eb64d67f..00000000 --- a/BinarySubTree_Java/nbproject/project.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - BSTree - - - - - - - - - .\lib\nblibraries.properties - - - diff --git a/BinarySubTree_Java/src/bstree/Main.java b/BinarySubTree_Java/src/bstree/Main.java deleted file mode 100644 index 21aa9a6f..00000000 --- a/BinarySubTree_Java/src/bstree/Main.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package bstree; - -import java.util.LinkedList; - -class Node { - - int info; - Node left, right; - - Node(int x) { - info = x; - left = right = null; - } -} - -class MyQueue { - - LinkedList a; - - MyQueue() { - a = new LinkedList(); - } - - boolean isEmpty() { - return (a.isEmpty()); - } - - void enqueue(Object x) { - a.add(x); - } - - Object dequeue() { - return (a.removeFirst()); - } -} - -class BTree { - - Node root; - - BTree() { - root = null; - } - - boolean isEmpty() { - return (root == null); - } - - Node search(Node p, int x) { - if (p == null) { - return (null); - } - if (p.info == x) { - return (p); - } - if (x < p.info) { - return (search(p.left, x)); - } else { - return (search(p.right, x)); - } - } - - void insert(int x) { - Node q = new Node(x); - if (isEmpty()) { - root = q; - return; - } - Node f, p; - f = null; - p = root; - while (p != null) { - if (p.info == x) { - System.out.println("The key " + x - + " already exists, no insertion"); - return; - } - f = p; - if (x < p.info) { - p = p.left; - } else { - p = p.right; - } - } - if (x < f.info) { - f.left = q; - } else { - f.right = q; - } - } - - void insertMany(int[] a) { - for (int i = 0; i < a.length; i++) { - insert(a[i]); - } - } - - void visit(Node p) { - System.out.print(p.info + " "); - } - - void preOrder(Node p) { - if (p == null) { - return; - } - visit(p); - preOrder(p.left); - preOrder(p.right); - } - - void inOrder(Node p) { - if (p == null) { - return; - } - inOrder(p.left); - visit(p); - inOrder(p.right); - } - - void postOrder(Node p) { - if (p == null) { - return; - } - postOrder(p.left); - postOrder(p.right); - visit(p); - } - - void breadth() { - if (root == null) { - return; - } - MyQueue q = new MyQueue(); - q.enqueue(root); - Node p; - while (!q.isEmpty()) { - p = (Node) q.dequeue(); - if (p.left != null) { - q.enqueue(p.left); - } - if (p.right != null) { - q.enqueue(p.right); - } - visit(p); - } - } - - Node deleteLeaves(Node root, int x) { - if (root == null) { - return null; - } - root.left = deleteLeaves(root.left, x); - root.right = deleteLeaves(root.right, x); - if (root.info == x && root.left == null && root.right == null) { - return null; - } - return root; - } -} - -public class Main { - - public static void main(String[] args) { - BTree t = new BTree(); - int[] a = {11, 5, 9, 7, 13}; - t.insertMany(a); - - /* 11 - Pre-order traverse 11 5 9 7 13 - / \ - In-order traverse 5 7 9 11 13 - 5 13 - Post-order traverse 7 9 5 13 11 - \ - Level-order traverse 11 5 13 9 7 - 9 (Breadth-first) - / - 7 - */ - System.out.print("BST after insertion (11 5 9 7 13):"); - System.out.print("\n - Pre-order traverse "); - t.preOrder(t.root); - System.out.print("\n - In-order traverse "); - t.inOrder(t.root); - System.out.print("\n - Post-order traverse "); - t.postOrder(t.root); - System.out.print("\n - Breadth-first traverse "); - t.breadth(); - System.out.print("\nBST after deletion 7:"); - t.deleteLeaves(t.root, 7); - System.out.print("\n - Pre-order traverse "); - t.preOrder(t.root); - System.out.print("\n - In-order traverse "); - t.inOrder(t.root); - System.out.print("\n - Post-order traverse "); - t.postOrder(t.root); - System.out.print("\n - Breadth-first traverse "); - t.breadth(); - System.out.println(); - } -} diff --git a/BinarySubTree_Java/src/deletionbymerging/Main.java b/Deletion In BST/Deletebymerging.java similarity index 100% rename from BinarySubTree_Java/src/deletionbymerging/Main.java rename to Deletion In BST/Deletebymerging.java diff --git a/BinarySubTree_Java/src/deletionbycopying/Main.java b/Deletion In BST/deletebycopying.java similarity index 100% rename from BinarySubTree_Java/src/deletionbycopying/Main.java rename to Deletion In BST/deletebycopying.java