diff --git a/.gitignore b/.gitignore index 524f096..cebe1ac 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/Sort.java b/Sort.java index 9c885bf..23b8ce9 100644 --- a/Sort.java +++ b/Sort.java @@ -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))); + } } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5dcbba1 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix index d981005..1c6c3e7 100644 --- a/flake.nix +++ b/flake.nix @@ -37,6 +37,7 @@ devTools = [ pkgs.google-java-format + pkgs.jdt-language-server ]; in