Compare commits

...

3 Commits

Author SHA1 Message Date
Ture Bentzin
dd7ad5f13a
update: implement sort algo 2025-11-20 17:04:26 +00:00
Ture Bentzin
9dff12dd0c
update: rename Main.java to Sort.java 2025-11-20 16:32:36 +00:00
Ture Bentzin
0793bd0eec
update: switch flake to Sort.java 2025-11-20 16:32:24 +00:00
5 changed files with 149 additions and 36 deletions

2
.gitignore vendored
View File

@ -22,3 +22,5 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
.direnv/

View File

@ -1,5 +0,0 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

38
Sort.java Normal file
View File

@ -0,0 +1,38 @@
import java.util.Arrays;
public class Sort {
private static int[] selectionSort1(int[] array) {
final int[] hilfsArray = new int[array.length];
while (array.length != 0) {
int indexKleinstesElement = 0;
for (int index = 1; index < array.length; index++) {
if (array[index] < array[indexKleinstesElement]) indexKleinstesElement = index;
}
// Add to hilfsarray (at curr pos)
hilfsArray[hilfsArray.length - array.length] = array[indexKleinstesElement];
System.out.println("Sortiere.... hilfsarray: " + Arrays.toString(hilfsArray) + " array: " + Arrays.toString(array));
// Refill array
int[] newArray = new int[array.length - 1];
// i = index in array, j = index in newArray
for (int i = 0, j = 0; i < array.length; i++ ) {
if (i != indexKleinstesElement) {
newArray[j] = array[i];
j++;
}
}
array = newArray;
}
return hilfsArray;
}
public static void main(String[] args) {
int[] input = new int[]{9,3,1,5};
System.out.println("Input: " + Arrays.toString(input));
System.out.println("Output: " + Arrays.toString(selectionSort1(input)));
}
}

61
flake.lock generated Normal file
View File

@ -0,0 +1,61 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1762980239,
"narHash": "sha256-8oNVE8TrD19ulHinjaqONf9QWCKK+w4url56cdStMpM=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "52a2caecc898d0b46b2b905f058ccc5081f842da",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1763421233,
"narHash": "sha256-Stk9ZYRkGrnnpyJ4eqt9eQtdFWRRIvMxpNRf4sIegnw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "89c2b2330e733d6cdb5eae7b899326930c2c0648",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1761765539,
"narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "719359f4562934ae99f5443f20aa06c2ffff91fc",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

View File

@ -6,51 +6,68 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = inputs@{ flake-parts, ... }:
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
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
perSystem =
{
config,
self',
inputs',
pkgs,
system,
...
}:
let
jdk = pkgs.jdk21.override {
};
jdk = pkgs.jdk21.override {
};
buildInputs = [
jdk
];
buildInputs = [
jdk
];
devTools = [
pkgs.google-java-format
];
devTools = [
pkgs.google-java-format
pkgs.jdt-language-server
];
in {
devShells.default = pkgs.mkShell {
buildInputs = buildInputs ++ devTools;
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = buildInputs ++ devTools;
};
packages = {
default = pkgs.stdenv.mkDerivation {
pname = "java-template";
version = "1.0.0";
packages = {
default = pkgs.stdenv.mkDerivation {
pname = "ssort";
version = "1.0.0";
src = ./.;
src = ./.;
nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ];
buildPhase = ''
javac -Werror -g:none -deprecation -verbose Main.java
'';
nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ];
installPhase = ''
mkdir -p $out/{bin,lib}
cp *.class $out/lib
buildPhase = ''
javac -Werror -g:none -deprecation -verbose Sort.java
'';
makeWrapper ${pkgs.lib.getExe jdk} $out/bin/java-template --add-flags "-cp $out/lib/ Main"
'';
installPhase = ''
mkdir -p $out/{bin,lib}
cp *.class $out/lib
makeWrapper ${pkgs.lib.getExe jdk} $out/bin/ssort --add-flags "-cp $out/lib/ Sort"
'';
};
};
};
};
flake = {
};
};