From cc226739a3bd72d3964436fe69567276592eedff Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Thu, 5 Feb 2026 22:10:39 +0100 Subject: [PATCH] Initial --- .envrc | 1 + .gitignore | 24 +++++++++++++++++++ BinaryTree.java | 49 +++++++++++++++++++++++++++++++++++++++ GNUmakefile | 12 ++++++++++ Main.java | 10 ++++++++ Node.java | 42 ++++++++++++++++++++++++++++++++++ binaryTree.md | 13 +++++++++++ flake.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 57 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 269 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 BinaryTree.java create mode 100644 GNUmakefile create mode 100644 Main.java create mode 100644 Node.java create mode 100644 binaryTree.md create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..524f096 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* diff --git a/BinaryTree.java b/BinaryTree.java new file mode 100644 index 0000000..b1cf257 --- /dev/null +++ b/BinaryTree.java @@ -0,0 +1,49 @@ +public class BinaryTree { + private Node rootNode = null; + + public BinaryTree() {} + + public BinaryTree(int content) { + insert(content); + } + + public void insert(int content) { + if (rootNode == null) { + Node newNode = new Node(content); + rootNode = newNode; + } else { + insertRecursiv(rootNode, content); + } + } + + private void insertRecursiv(Node currentNode, int content) { + int currentContent = currentNode.getContent(); + + // has to be inserted left + if (currentContent <= content) { + // if node == null -> insert left + if (currentNode.getLeftNode() == null) { + Node newNode = new Node(content); + currentNode.setLeftNode(newNode); + System.out.println("Inserted Left"); + return; + } else { + // traverse -> 1 down + insertRecursiv(currentNode.getLeftNode(), content); + return; + } + } else /* insert right */ { + // if node == null -> insert right + if (currentNode.getRightNode() == null) { + Node newNode = new Node(content); + currentNode.setRightNode(newNode); + System.out.println("Inserted Right"); + return; + } else { + // traverse -> 1 down + insertRecursiv(currentNode.getRightNode(), content); + return; + } + } + } +} diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..2ab9f2e --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,12 @@ +JAVA_FMT = google-java-format +JAVA_FILES = $(shell find . -name '*.java') +XML_FMT = xmlindent +XML_FILES = $(shell find . -name '*.xml') + +.PHONY: fmt +fmt: + @echo "Formatting all Java files..." + @for f in $(JAVA_FILES); do \ + echo " $$f"; \ + $(JAVA_FMT) -i $$f; \ + done diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..c413861 --- /dev/null +++ b/Main.java @@ -0,0 +1,10 @@ +public class Main { + public static void main(String[] args) { + BinaryTree binaryTree = new BinaryTree(23); + binaryTree.insert(42); + binaryTree.insert(23); + binaryTree.insert(22); + binaryTree.insert(23); + binaryTree.insert(55); + } +} diff --git a/Node.java b/Node.java new file mode 100644 index 0000000..090a842 --- /dev/null +++ b/Node.java @@ -0,0 +1,42 @@ +public class Node { + private int content; + private Node leftNode; + private Node rightNode; + + public Node() {} + + public Node(int content) { + setContent(content); + } + + public int getContent() { + return content; + } + + public void setContent(int content) { + this.content = content; + } + + public Node getLeftNode() { + return leftNode; + } + + public Node getRightNode() { + return rightNode; + } + + public boolean isEmpty() { + if (leftNode == null && rightNode == null) { + return true; + } + return false; + } + + public void setRightNode(Node node) { + rightNode = node; + } + + public void setLeftNode(Node node) { + leftNode = node; + } +} diff --git a/binaryTree.md b/binaryTree.md new file mode 100644 index 0000000..f1f198d --- /dev/null +++ b/binaryTree.md @@ -0,0 +1,13 @@ ++---------------------------------------+ +| BinaryTree | ++---------------------------------------+ +| - root Node (int) | +| | ++---------------------------------------+ +| | +| - Node | +| - content int | +| - leftChild Node | +| - rightChild Node | ++---------------------------------------+ + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..06b68cb --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1769996383, + "narHash": "sha256-AnYjnFWgS49RlqX7LrC4uA+sCCDBj0Ry/WOJ5XWAsa0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "57928607ea566b5db3ad13af0e57e921e6b12381", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1770115704, + "narHash": "sha256-KHFT9UWOF2yRPlAnSXQJh6uVcgNcWlFqqiAZ7OVlHNc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e6eae2ee2110f3d31110d5c222cd395303343b08", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1769909678, + "narHash": "sha256-cBEymOf4/o3FD5AZnzC3J9hLbiZ+QDT/KDuyHXVJOpM=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "72716169fe93074c333e8d0173151350670b824c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e044a99 --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + description = "tree"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + ]; + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + perSystem = { config, self', inputs', pkgs, system, ... }: let + + jdk = pkgs.jdk21.override { + }; + + buildInputs = [ + jdk + ]; + + devTools = [ + pkgs.google-java-format + ]; + + in { + devShells.default = pkgs.mkShell { + buildInputs = buildInputs ++ devTools; + }; + + packages = { + default = pkgs.stdenv.mkDerivation { + pname = "tree"; + version = "1.0.0"; + + src = ./.; + + nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ]; + + buildPhase = '' + javac -Werror -g:none -deprecation -verbose Main.java + ''; + + installPhase = '' + mkdir -p $out/{bin,lib} + cp *.class $out/lib + + makeWrapper ${pkgs.lib.getExe jdk} $out/bin/tree --add-flags "-cp $out/lib/ Main" + ''; + }; + }; + }; + flake = { + }; + }; +}