diff --git a/.classpath b/.classpath deleted file mode 100644 index 67d5f6d3..00000000 --- a/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/.gitignore b/.gitignore index ae3c1726..bf2ba945 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ /bin/ +.idea/* +.classpath* +.project* +*.iml diff --git a/.project b/.project deleted file mode 100644 index ea54703d..00000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - Java - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/Searches/src/search/BinarySearch.java b/Searches/BinarySearch.java similarity index 99% rename from Searches/src/search/BinarySearch.java rename to Searches/BinarySearch.java index 239bc98c..f655c074 100644 --- a/Searches/src/search/BinarySearch.java +++ b/Searches/BinarySearch.java @@ -1,4 +1,4 @@ -package search; +package Searches; import java.util.Arrays; import java.util.Random; diff --git a/Searches/src/search/InterpolationSearch.java b/Searches/InterpolationSearch.java similarity index 99% rename from Searches/src/search/InterpolationSearch.java rename to Searches/InterpolationSearch.java index 06313d13..b2395797 100644 --- a/Searches/src/search/InterpolationSearch.java +++ b/Searches/InterpolationSearch.java @@ -1,4 +1,4 @@ -package search; +package Searches; import java.util.Arrays; import java.util.Random; diff --git a/Searches/src/search/IterativeBinarySearch.java b/Searches/IterativeBinarySearch.java similarity index 99% rename from Searches/src/search/IterativeBinarySearch.java rename to Searches/IterativeBinarySearch.java index 17bfe395..c6f8e7f1 100644 --- a/Searches/src/search/IterativeBinarySearch.java +++ b/Searches/IterativeBinarySearch.java @@ -1,4 +1,4 @@ -package search; +package Searches; import java.util.Arrays; import java.util.Random; diff --git a/Searches/src/search/IterativeTernarySearch.java b/Searches/IterativeTernarySearch.java similarity index 99% rename from Searches/src/search/IterativeTernarySearch.java rename to Searches/IterativeTernarySearch.java index c3538e69..598b3b3e 100644 --- a/Searches/src/search/IterativeTernarySearch.java +++ b/Searches/IterativeTernarySearch.java @@ -1,4 +1,4 @@ -package search; +package Searches; import java.util.Arrays; import java.util.Random; diff --git a/Searches/src/search/LinearSearch.java b/Searches/LinearSearch.java similarity index 98% rename from Searches/src/search/LinearSearch.java rename to Searches/LinearSearch.java index 6e96da0f..7664d7de 100644 --- a/Searches/src/search/LinearSearch.java +++ b/Searches/LinearSearch.java @@ -1,4 +1,4 @@ -package search; +package Searches; import java.util.Random; import java.util.stream.Stream; diff --git a/Searches/src/search/SaddlebackSearch.java b/Searches/SaddlebackSearch.java similarity index 99% rename from Searches/src/search/SaddlebackSearch.java rename to Searches/SaddlebackSearch.java index 68779db8..ed9c9108 100644 --- a/Searches/src/search/SaddlebackSearch.java +++ b/Searches/SaddlebackSearch.java @@ -1,4 +1,4 @@ -package search; +package Searches; import java.util.Scanner; diff --git a/Searches/src/search/SearchAlgorithm.java b/Searches/SearchAlgorithm.java similarity index 96% rename from Searches/src/search/SearchAlgorithm.java rename to Searches/SearchAlgorithm.java index ca3bf59b..d1a93fb7 100644 --- a/Searches/src/search/SearchAlgorithm.java +++ b/Searches/SearchAlgorithm.java @@ -1,4 +1,4 @@ -package search; +package Searches; /** * The common interface of most searching algorithms diff --git a/Searches/src/search/TernarySearch.java b/Searches/TernarySearch.java similarity index 99% rename from Searches/src/search/TernarySearch.java rename to Searches/TernarySearch.java index 7e60edf3..cefd3740 100644 --- a/Searches/src/search/TernarySearch.java +++ b/Searches/TernarySearch.java @@ -1,4 +1,4 @@ -package search; +package Searches; import java.util.Arrays; diff --git a/SkylineProblem/SkylineProblem.java b/SkylineProblem/SkylineProblem.java deleted file mode 100644 index 121116e1..00000000 --- a/SkylineProblem/SkylineProblem.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Given n rectangular buildings in a 2-dimensional city, computes the skyline of these buildings, - * eliminating hidden lines. The main task is to view buildings from a side and remove all sections - * that are not visible. - * Source for explanation: https://www.geeksforgeeks.org/the-skyline-problem-using-divide-and-conquer-algorithm/ - */ -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Scanner; - -public class SkylineProblem { - Building[] building; - int count; - - public void run() { - Scanner sc = new Scanner(System.in); - - int num = sc.nextInt(); - this.building = new Building[num]; - - for(int i = 0; i < num; i++) { - String input = sc.next(); - String[] data = input.split(","); - this.add(Integer.parseInt(data[0]), Integer.parseInt(data[1]), Integer.parseInt(data[2])); - } - this.print(this.findSkyline(0, num - 1)); - - sc.close(); - } - - public void add(int left, int height, int right) { - building[count++] = new Building(left, height, right); - } - - public void print(ArrayList skyline) { - Iterator it = skyline.iterator(); - - while(it.hasNext()) { - Skyline temp = it.next(); - System.out.print(temp.coordinates + "," + temp.height); - if(it.hasNext()) { - System.out.print(","); - } - } - - } - - public ArrayList findSkyline(int start, int end) { - if(start == end) { - ArrayList list = new ArrayList<>(); - list.add(new Skyline(building[start].left, building[start].height)); - list.add(new Skyline(building[end].right, 0)); - - return list; - } - - int mid = (start + end) / 2; - - ArrayList sky1 = this.findSkyline(start, mid); - ArrayList sky2 = this.findSkyline(mid + 1, end); - - return this.mergeSkyline(sky1, sky2); - } - - public ArrayList mergeSkyline(ArrayList sky1, ArrayList sky2) { - int currentH1 = 0, currentH2 = 0; - ArrayList skyline = new ArrayList<>(); - int maxH = 0; - - while(!sky1.isEmpty() && !sky2.isEmpty()) { - if(sky1.get(0).coordinates < sky2.get(0).coordinates) { - int currentX = sky1.get(0).coordinates; - currentH1 = sky1.get(0).height; - - if(currentH1 < currentH2) { - sky1.remove(0); - if(maxH != currentH2) skyline.add(new Skyline(currentX, currentH2)); - } else { - maxH = currentH1; - sky1.remove(0); - skyline.add(new Skyline(currentX, currentH1)); - } - } else { - int currentX = sky2.get(0).coordinates; - currentH2 = sky2.get(0).height; - - if(currentH2 < currentH1) { - sky2.remove(0); - if(maxH != currentH1) skyline.add(new Skyline(currentX, currentH1)); - } else { - maxH = currentH2; - sky2.remove(0); - skyline.add(new Skyline(currentX, currentH2)); - } - } - } - - while(!sky1.isEmpty()) { - skyline.add(sky1.get(0)); - sky1.remove(0); - } - - while(!sky2.isEmpty()) { - skyline.add(sky2.get(0)); - sky2.remove(0); - } - - return skyline; - } - - public class Skyline { - public int coordinates; - public int height; - - public Skyline(int coordinates, int height) { - this.coordinates = coordinates; - this.height = height; - } - } - - public class Building { - public int left; - public int height; - public int right; - - public Building(int left, int height, int right) { - this.left = left; - this.height = height; - this.right = right; - } - } - - public static void main(String[] args) { - SkylineProblem skylineProblem = new SkylineProblem(); - skylineProblem.run(); - } -} diff --git a/Sorts/src/sort/BinaryTreeSort.java b/Sorts/BinaryTreeSort.java similarity index 95% rename from Sorts/src/sort/BinaryTreeSort.java rename to Sorts/BinaryTreeSort.java index 59d58ab6..26942754 100644 --- a/Sorts/src/sort/BinaryTreeSort.java +++ b/Sorts/BinaryTreeSort.java @@ -1,7 +1,7 @@ -package sort; +package Sorts; -import static sort.SortUtils.less; -import static sort.SortUtils.print; +import static Sorts.SortUtils.less; +import static Sorts.SortUtils.print; /** * diff --git a/Sorts/src/sort/BogoSort.java b/Sorts/BogoSort.java similarity index 82% rename from Sorts/src/sort/BogoSort.java rename to Sorts/BogoSort.java index 1079ca21..f3f923d3 100644 --- a/Sorts/src/sort/BogoSort.java +++ b/Sorts/BogoSort.java @@ -1,9 +1,7 @@ -package sort; +package Sorts; import java.util.Random; -import static sort.SortUtils.*; - /** * @@ -19,7 +17,7 @@ public class BogoSort implements SortAlgorithm { private static > boolean isSorted(T array[]){ for(int i = 0; i left; j--) { - if (less(array[j], array[j - 1])) { - swap(array, j - 1, j); + if (SortUtils.less(array[j], array[j - 1])) { + SortUtils.swap(array, j - 1, j); swappedLeft = j; } } @@ -56,11 +54,11 @@ class CocktailShakerSort implements SortAlgorithm { CocktailShakerSort shakerSort = new CocktailShakerSort(); // Output => 1 4 6 9 12 23 54 78 231 - print(shakerSort.sort(integers)); + SortUtils.print(shakerSort.sort(integers)); // String Input String[] strings = { "c", "a", "e", "b", "d" }; - print(shakerSort.sort(strings)); + SortUtils.print(shakerSort.sort(strings)); } diff --git a/Sorts/src/sort/CombSort.java b/Sorts/CombSort.java similarity index 97% rename from Sorts/src/sort/CombSort.java rename to Sorts/CombSort.java index 492605ca..83e24eda 100644 --- a/Sorts/src/sort/CombSort.java +++ b/Sorts/CombSort.java @@ -1,6 +1,6 @@ -package sort; +package Sorts; -import static sort.SortUtils.*; +import static Sorts.SortUtils.*; /** diff --git a/Sorts/src/sort/CountingSort.java b/Sorts/CountingSort.java similarity index 98% rename from Sorts/src/sort/CountingSort.java rename to Sorts/CountingSort.java index 39442a00..7243a27a 100644 --- a/Sorts/src/sort/CountingSort.java +++ b/Sorts/CountingSort.java @@ -1,4 +1,4 @@ -package sort; +package Sorts; import java.util.*; import java.util.stream.IntStream; @@ -6,7 +6,7 @@ import java.util.stream.Stream; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; -import static sort.SortUtils.print; +import static Sorts.SortUtils.print; /** * diff --git a/Sorts/src/sort/CycleSort.java b/Sorts/CycleSort.java similarity index 95% rename from Sorts/src/sort/CycleSort.java rename to Sorts/CycleSort.java index ea4f0553..eba541a0 100644 --- a/Sorts/src/sort/CycleSort.java +++ b/Sorts/CycleSort.java @@ -1,7 +1,7 @@ -package sort; +package Sorts; -import static sort.SortUtils.less; -import static sort.SortUtils.print; +import static Sorts.SortUtils.less; +import static Sorts.SortUtils.print; /** * @author Podshivalov Nikita (https://github.com/nikitap492) diff --git a/Sorts/src/sort/GnomeSort.java b/Sorts/GnomeSort.java similarity index 95% rename from Sorts/src/sort/GnomeSort.java rename to Sorts/GnomeSort.java index 14af67c6..ef5dca14 100644 --- a/Sorts/src/sort/GnomeSort.java +++ b/Sorts/GnomeSort.java @@ -1,6 +1,6 @@ -package sort; +package Sorts; -import static sort.SortUtils.*; +import static Sorts.SortUtils.*; /** * Implementation of gnome sort diff --git a/Sorts/src/sort/HeapSort.java b/Sorts/HeapSort.java similarity index 98% rename from Sorts/src/sort/HeapSort.java rename to Sorts/HeapSort.java index 6fab3747..9be2c2e7 100644 --- a/Sorts/src/sort/HeapSort.java +++ b/Sorts/HeapSort.java @@ -1,10 +1,10 @@ -package sort; +package Sorts; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static sort.SortUtils.*; +import static Sorts.SortUtils.*; /** * Heap Sort Algorithm diff --git a/Sorts/src/sort/InsertionSort.java b/Sorts/InsertionSort.java similarity index 93% rename from Sorts/src/sort/InsertionSort.java rename to Sorts/InsertionSort.java index 59361430..f29c3537 100644 --- a/Sorts/src/sort/InsertionSort.java +++ b/Sorts/InsertionSort.java @@ -1,7 +1,7 @@ -package sort; +package Sorts; -import static sort.SortUtils.less; -import static sort.SortUtils.print; +import static Sorts.SortUtils.less; +import static Sorts.SortUtils.print; /** * diff --git a/Sorts/src/sort/MergeSort.java b/Sorts/MergeSort.java similarity index 98% rename from Sorts/src/sort/MergeSort.java rename to Sorts/MergeSort.java index 2c7a141b..3c4fa4a2 100644 --- a/Sorts/src/sort/MergeSort.java +++ b/Sorts/MergeSort.java @@ -1,6 +1,6 @@ -package sort; +package Sorts; -import static sort.SortUtils.print; +import static Sorts.SortUtils.print; /** * This method implements the Generic Merge Sort diff --git a/Sorts/src/sort/PancakeSort.java b/Sorts/PancakeSort.java similarity index 95% rename from Sorts/src/sort/PancakeSort.java rename to Sorts/PancakeSort.java index 902db4b3..395b75f9 100644 --- a/Sorts/src/sort/PancakeSort.java +++ b/Sorts/PancakeSort.java @@ -1,6 +1,6 @@ -package sort; +package Sorts; -import static sort.SortUtils.*; +import static Sorts.SortUtils.*; /** * Implementation of gnome sort diff --git a/Sorts/src/sort/QuickSort.java b/Sorts/QuickSort.java similarity index 97% rename from Sorts/src/sort/QuickSort.java rename to Sorts/QuickSort.java index 4159fc82..36b042c1 100644 --- a/Sorts/src/sort/QuickSort.java +++ b/Sorts/QuickSort.java @@ -1,6 +1,6 @@ -package sort; +package Sorts; -import static sort.SortUtils.*; +import static Sorts.SortUtils.*; /** * diff --git a/Sorts/src/sort/RadixSort.java b/Sorts/RadixSort.java similarity index 98% rename from Sorts/src/sort/RadixSort.java rename to Sorts/RadixSort.java index 0d1e6966..9fd1ab7b 100644 --- a/Sorts/src/sort/RadixSort.java +++ b/Sorts/RadixSort.java @@ -1,4 +1,4 @@ -package sort; +package Sorts; import java.util.Arrays; diff --git a/Sorts/src/sort/SelectionSort.java b/Sorts/SelectionSort.java similarity index 87% rename from Sorts/src/sort/SelectionSort.java rename to Sorts/SelectionSort.java index 960215a6..7ab599f9 100644 --- a/Sorts/src/sort/SelectionSort.java +++ b/Sorts/SelectionSort.java @@ -1,6 +1,4 @@ -package sort; - -import static sort.SortUtils.*; +package Sorts; /** * @@ -27,14 +25,14 @@ public class SelectionSort implements SortAlgorithm { int min = i; for (int j = i +1 ; j < n; j++) { - if (less(arr[j], arr[min])) { + if (SortUtils.less(arr[j], arr[min])) { min = j; } } // Swapping if index of min is changed if (min != i) { - swap(arr, i , min); + SortUtils.swap(arr, i , min); } } @@ -51,13 +49,13 @@ public class SelectionSort implements SortAlgorithm { Integer[] sorted = selectionSort.sort(arr); // Output => 1 4 6 9 12 23 54 78 231 - print(sorted); + SortUtils.print(sorted); // String Input String[] strings = {"c", "a", "e", "b","d"}; String[] sortedStrings = selectionSort.sort(strings); //Output => a b c d e - print(sortedStrings); + SortUtils.print(sortedStrings); } } diff --git a/Sorts/src/sort/ShellSort.java b/Sorts/ShellSort.java similarity index 94% rename from Sorts/src/sort/ShellSort.java rename to Sorts/ShellSort.java index bafd19b1..31c2c607 100644 --- a/Sorts/src/sort/ShellSort.java +++ b/Sorts/ShellSort.java @@ -1,6 +1,6 @@ -package sort; +package Sorts; -import static sort.SortUtils.*; +import static Sorts.SortUtils.*; /** diff --git a/Sorts/src/sort/SortAlgorithm.java b/Sorts/SortAlgorithm.java similarity index 98% rename from Sorts/src/sort/SortAlgorithm.java rename to Sorts/SortAlgorithm.java index 46b1f58e..e6004156 100644 --- a/Sorts/src/sort/SortAlgorithm.java +++ b/Sorts/SortAlgorithm.java @@ -1,4 +1,4 @@ -package sort; +package Sorts; import java.util.Arrays; import java.util.List; diff --git a/Sorts/src/sort/SortUtils.java b/Sorts/SortUtils.java similarity index 99% rename from Sorts/src/sort/SortUtils.java rename to Sorts/SortUtils.java index 8766e9d0..b3392352 100644 --- a/Sorts/src/sort/SortUtils.java +++ b/Sorts/SortUtils.java @@ -1,4 +1,4 @@ -package sort; +package Sorts; import java.util.Arrays; import java.util.List;