Initial
This commit is contained in:
commit
cc226739a3
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@ -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*
|
||||
49
BinaryTree.java
Normal file
49
BinaryTree.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
GNUmakefile
Normal file
12
GNUmakefile
Normal file
@ -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
|
||||
10
Main.java
Normal file
10
Main.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
42
Node.java
Normal file
42
Node.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
13
binaryTree.md
Normal file
13
binaryTree.md
Normal file
@ -0,0 +1,13 @@
|
||||
+---------------------------------------+
|
||||
| BinaryTree |
|
||||
+---------------------------------------+
|
||||
| - root Node (int) |
|
||||
| |
|
||||
+---------------------------------------+
|
||||
| |
|
||||
| - Node |
|
||||
| - content int |
|
||||
| - leftChild Node |
|
||||
| - rightChild Node |
|
||||
+---------------------------------------+
|
||||
|
||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@ -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
|
||||
}
|
||||
57
flake.nix
Normal file
57
flake.nix
Normal file
@ -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 = {
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user