From a5526f63beac15c35ef900d0f6b38df7b21e0914 Mon Sep 17 00:00:00 2001 From: "sailok.chinta" Date: Thu, 3 Oct 2024 13:13:10 +0530 Subject: [PATCH 1/2] feat: Remove duplicate implementation of Dutch National Flag Sort Algorithm --- .../java/com/thealgorithms/misc/Sort012D.java | 63 ------------------- 1 file changed, 63 deletions(-) delete mode 100644 src/main/java/com/thealgorithms/misc/Sort012D.java diff --git a/src/main/java/com/thealgorithms/misc/Sort012D.java b/src/main/java/com/thealgorithms/misc/Sort012D.java deleted file mode 100644 index 706e877e40c1..000000000000 --- a/src/main/java/com/thealgorithms/misc/Sort012D.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.thealgorithms.misc; - -import java.util.Scanner; - -/** - * The array is divided into four sections: a[1..Lo-1] zeroes a[Lo..Mid-1] ones - * a[Mid..Hi] unknown a[Hi+1..N] twos If array [mid] =0, then swap array [mid] - * with array [low] and increment both pointers once. If array [mid] = 1, then - * no swapping is required. Increment mid pointer once. If array [mid] = 2, then - * we swap array [mid] with array [high] and decrement the high pointer once. - * For more information on the Dutch national flag algorithm refer - * https://en.wikipedia.org/wiki/Dutch_national_flag_problem - */ -public final class Sort012D { - private Sort012D() { - } - - public static void main(String[] args) { - Scanner np = new Scanner(System.in); - int n = np.nextInt(); - int[] a = new int[n]; - for (int i = 0; i < n; i++) { - a[i] = np.nextInt(); - } - sort012(a); - np.close(); - } - - public static void sort012(int[] a) { - int l = 0; - int h = a.length - 1; - int mid = 0; - int temp; - while (mid <= h) { - switch (a[mid]) { - case 0: - temp = a[l]; - a[l] = a[mid]; - a[mid] = temp; - l++; - mid++; - break; - - case 1: - mid++; - break; - case 2: - temp = a[mid]; - a[mid] = a[h]; - a[h] = temp; - h--; - break; - - default: - throw new IllegalArgumentException("Unexpected value: " + a[mid]); - } - } - System.out.println("the Sorted array is "); - for (int i = 0; i < a.length; i++) { - System.out.print(+a[i] + " "); - } - } -} From 5ced7e789873c5df43d50a34f811667997cc460b Mon Sep 17 00:00:00 2001 From: "sailok.chinta" Date: Thu, 3 Oct 2024 13:15:38 +0530 Subject: [PATCH 2/2] feat: update DIRECTORY.md --- DIRECTORY.md | 1 - 1 file changed, 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 6f63a88b085a..2a87031d9332 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -397,7 +397,6 @@ * [PalindromePrime](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/PalindromePrime.java) * [PalindromeSinglyLinkedList](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java) * [RangeInSortedArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/RangeInSortedArray.java) - * [Sort012D](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/Sort012D.java) * [Sparsity](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/Sparsity.java) * [ThreeSumProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java) * [TwoSumProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/TwoSumProblem.java)