update: implement sort algo

This commit is contained in:
Ture Bentzin 2025-11-20 17:04:26 +00:00
parent 9dff12dd0c
commit dd7ad5f13a
No known key found for this signature in database
GPG Key ID: F1E670A1ED8E92CE
4 changed files with 100 additions and 3 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 +1,38 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
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

@ -37,6 +37,7 @@
devTools = [
pkgs.google-java-format
pkgs.jdt-language-server
];
in