Inital commit

This commit is contained in:
Dawid Urbaniak 2024-06-21 13:30:48 +02:00
commit 9adb4a81e1
17 changed files with 521 additions and 0 deletions

29
.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Paradygmaty_Programowania_1.iml" filepath="$PROJECT_DIR$/Paradygmaty_Programowania_1.iml" />
</modules>
</component>
</project>

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

16
src/Bubble_Sort.java Normal file
View File

@ -0,0 +1,16 @@
import java.util.Comparator;
public class Bubble_Sort {
public static <T> void bubble_sort(T[] array, Comparator<T> comparator) {
int array_length = array.length;
for (int i = 0; i < array_length; i++) {
for (int j = 0; j < array_length - 1 - i; j++) {
if (comparator.compare(array[j], array[j + 1]) > 0) {
T temporary = array[j];
array[j] = array[j + 1];
array[j + 1] = temporary;
}
}
}
}
}

30
src/Bucket_Sort.java Normal file
View File

@ -0,0 +1,30 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class Bucket_Sort {
public static <T> void bucket_sort(T[] array, Comparator<T> comparator) {
int array_length = array.length;
List<T>[] bucket = new ArrayList[array_length];
for (int i = 0; i < array_length; i++) {
bucket[i] = new ArrayList<>();
}
for (T elem : array) {
int bucket_index = (int) (array_length * (Float) elem);
bucket[bucket_index].add(elem);
}
for (List<T> container : bucket) {
container.sort(comparator);
}
int index_to_add = 0;
for (List<T> container : bucket) {
for (T item : container) {
array[index_to_add++] = item;
}
}
}
}

39
src/Counting_Sort.java Normal file
View File

@ -0,0 +1,39 @@
import java.util.Arrays;
import java.util.Comparator;
public class Counting_Sort {
public static <T> void counting_sort(T[] array, Comparator<T> comparator){
int array_length = array.length;
T min = array[0];
T max = array[0];
for (int i = 1; i < array.length; i ++) {
if (comparator.compare(array[i], min) < 0) {
min = array[i];
}
if (comparator.compare(array[i], max) > 0) {
max=array[i];
}
}
int []counting_array = new int[array_length];
Arrays.fill(counting_array, 0);
for (T value : array) {
int every_index = Arrays.binarySearch(array, min, comparator);
counting_array[every_index]++;
}
for (int i = 1; i < array_length; i++) {
counting_array[i] += counting_array[i - 1];
}
T[] array_copy = array;
for (int i = array_length - 1; i >= 0; i--) {
int index = Arrays.binarySearch(array, min, comparator);
array_copy[--counting_array[index]] = array[i];
}
System.arraycopy(array_copy, 0, array, 0, array_length);
}
}

40
src/Heap_Sort.java Normal file
View File

@ -0,0 +1,40 @@
import java.util.Comparator;
public class Heap_Sort {
public static <T> void heap_sort(T[] array, Comparator<T> comparator) {
int array_length = array.length;
for (int i = array_length / 2 - 1; i >= 0; i--) {
heaping(array, array_length, i, comparator);
}
for (int i = array_length - 1; i > 0; i--) {
T temporary = array[0];
array[0] = array[i];
array[i] = temporary;
heaping(array, i, 0, comparator);
}
}
private static <T> void heaping(T[] array, int array_length, int i, Comparator<T> comparator) {
int max = i;
int left = 2 * i + 1;
int right = 2 * i + 2;
if (left < array_length && comparator.compare(array[left], array[max]) > 0) {
max = left;
}
if(right < array_length && comparator.compare(array[right], array[max]) > 0) {
max = right;
}
if (max != i) {
T temporary = array[i];
array[i] = array[max];
array[max] = temporary;
heaping(array, array_length, max, comparator);
}
}
}

15
src/Insert_Sort.java Normal file
View File

@ -0,0 +1,15 @@
import java.util.Comparator;
public class Insert_Sort {
public static <T> void insertion_sort(T[] array, Comparator<T> comparator) {
for (int i = 1; i < array.length; i++) {
T actual_element = array[i];
int previous_index = i - 1;
while (previous_index >= 0 && comparator.compare(array[previous_index], actual_element) > 0) {
array[previous_index + 1] = array[i-1];
previous_index++;
}
array[previous_index + 1] = actual_element;
}
}
}

60
src/Main.java Normal file
View File

@ -0,0 +1,60 @@
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Integer[] some_array = {21,4,33,56,2,1,7,15};
System.out.println("Original Array: " + Arrays.toString(some_array));
System.out.println("--------------------------------------------------------------");
Integer[] array_bubble = some_array;
Bubble_Sort.bubble_sort(array_bubble, Integer::compareTo);
System.out.println("After Bubble Sort: " + Arrays.toString(array_bubble));
System.out.println("--------------------------------------------------------------");
Integer[] array_selection_sort = some_array;
Selection_Sort.selection_sort(array_selection_sort, Integer::compareTo);
System.out.println("After Selection Sort: " + Arrays.toString(array_selection_sort));
System.out.println("--------------------------------------------------------------");
Integer[] array_counting_sort = some_array;
Counting_Sort.counting_sort(array_counting_sort, Integer::compareTo);
System.out.println("After Counting Sort: " + Arrays.toString(array_counting_sort));
System.out.println("--------------------------------------------------------------");
Integer[] array_quick_sort = some_array;
int array_length = some_array.length;
Quick_Sort.quick_sort(array_quick_sort, 0, array_length -1, Integer::compareTo);
System.out.println("After Quick Sort: " + Arrays.toString(array_quick_sort));
System.out.println("--------------------------------------------------------------");
Integer[] array_merge_sort = some_array;
Merge_Sort.merge_sort(array_merge_sort, Integer::compareTo);
System.out.println("After Merge Sort: " + Arrays.toString(array_merge_sort));
System.out.println("--------------------------------------------------------------");
Integer[] array_insert_sort = some_array;
Insert_Sort.insertion_sort(array_insert_sort, Integer::compareTo);
System.out.println("After Insert Sort: " + Arrays.toString(array_insert_sort));
System.out.println("--------------------------------------------------------------");
Float[] array_bucket_sort = {0.123f, 0.003f, 0.435f, 0.234f, 0.124f, 0.678f, 0.567f };
Bucket_Sort.bucket_sort(array_bucket_sort, Float::compareTo);
System.out.println("After Bucket Sort: " + Arrays.toString(array_bucket_sort));
System.out.println("--------------------------------------------------------------");
Integer[] array_radix_sort = some_array;
Radix_Sort.radix_sort(array_radix_sort, Integer::compareTo);
System.out.println("After Radix Sort: " + Arrays.toString(array_radix_sort));
System.out.println("--------------------------------------------------------------");
Integer[] array_heap_sort = some_array;
Heap_Sort.heap_sort(array_heap_sort, Integer::compareTo);
System.out.println("After Heap Sort: " + Arrays.toString(array_heap_sort));
System.out.println("--------------------------------------------------------------");
Integer[] array_shell_sort = some_array;
Shell_Sort.shell_Sort(array_shell_sort, Integer::compareTo);
System.out.println("After Shell Sort: " + Arrays.toString(array_shell_sort));
System.out.println("--------------------------------------------------------------");
}
}

39
src/Merge_Sort.java Normal file
View File

@ -0,0 +1,39 @@
import java.util.Arrays;
import java.util.Comparator;
public class Merge_Sort {
public static <T> void merge_sort(T[] array, Comparator<T> comparator) {
T[] temporary_array = Arrays.copyOf(array, array.length);
int start_index = 0;
int end_index = array.length - 1;
sort(array, temporary_array, start_index, end_index, comparator);
}
private static <T> void sort(T[] array, T[] temporary_array, int start_index, int end_index, Comparator<T> comparator ) {
if (start_index >= end_index) return;
int middle_index = (start_index + end_index) / 2;
sort(array, temporary_array, start_index, middle_index, comparator);
sort(array, temporary_array, middle_index + 1, end_index, comparator);
merge(array, temporary_array, start_index, middle_index, end_index, comparator);
}
private static <T> void merge(T[] array, T[] temporary_array, int start_index, int middle_index, int end_index, Comparator<T> comparator ) {
int left_index_end = middle_index;
int right_index_start = middle_index + 1;
int left_index = start_index;
int right_indext = right_index_start;
int actual_index = start_index;
while (left_index <= left_index_end && right_indext <= end_index) {
if (comparator.compare(array[left_index], array[right_indext]) <= 0) {
temporary_array[actual_index++] = array[left_index++];
} else {
temporary_array[actual_index++] = array[right_indext++];
}
}
System.arraycopy(array, left_index, temporary_array, actual_index, left_index_end - left_index + 1);
System.arraycopy(array, right_indext, temporary_array, actual_index, end_index - right_indext + 1);
System.arraycopy(temporary_array, start_index, array, start_index, end_index - start_index + 1);
}
}

27
src/Quick_Sort.java Normal file
View File

@ -0,0 +1,27 @@
import java.util.Comparator;
public class Quick_Sort {
public static <T> void quick_sort(T[] array, int start_index, int end_index, Comparator<T> comparator) {
if (start_index < end_index) {
T pivot = array[end_index];
int pivot_index = start_index - 1;
for (int j = start_index; j <= end_index - 1; j++) {
if (comparator.compare(array[j], pivot) < 0) {
pivot_index++;
T temp = array[pivot_index];
array[pivot_index] = array[j];
array[j] = temp;
}
}
T temp = array[pivot_index + 1];
array[pivot_index + 1] = array[end_index];
array[end_index] = temp;
int index = pivot_index + 1;
quick_sort(array, start_index, index - 1, comparator);
quick_sort(array, index + 1, end_index, comparator);
}
}
}

34
src/Radix_Sort.java Normal file
View File

@ -0,0 +1,34 @@
import java.util.Arrays;
import java.util.Comparator;
public class Radix_Sort {
public static void radix_sort(Integer[] array, Comparator<Integer> comparator) {
int array_length = array.length;
int maximum = Arrays.stream(array).max(comparator).orElse(array[0]);
for(int i = 1; maximum / i > 0; i *= 10) {
count_sort(array, array_length, i, comparator);
}
}
private static void count_sort(Integer[] array, int array_length, int i, Comparator<Integer> comparator ) {
Integer[] final_array = new Integer[array_length];
int[] coutning = new int[10];
Arrays.fill(coutning, 0);
for (int j = 0; j < array_length; j++) {
coutning[(array[j] / i) % 10]++;
}
for (int k = 1; k < 10; k++) {
coutning[k] += coutning[k - 1];
}
for (int l = array_length - 1; l >= 0; l--) {
final_array[coutning[(array[l] / i) % 10] - 1] = array[l];
coutning[(array[l] / i) % 10]--;
}
System.arraycopy(final_array, 0, array, 0, array_length);
}
}

18
src/Selection_Sort.java Normal file
View File

@ -0,0 +1,18 @@
import java.util.Comparator;
public class Selection_Sort {
public static <T> void selection_sort(T[] array, Comparator<T> comparator) {
int array_length = array.length;
for (int i = 0; i < array_length - 1; i++) {
int min_index = i;
for (int j = i + 1; j < array_length; j++) {
if (comparator.compare(array[j], array[min_index]) < 0) {
min_index = j;
}
}
T temporary = array[min_index];
array[min_index] = array[i];
array[i] = temporary;
}
}
}

17
src/Shell_Sort.java Normal file
View File

@ -0,0 +1,17 @@
import java.util.Comparator;
public class Shell_Sort {
public static <T> void shell_Sort(T[] array, Comparator<T> comparator) {
int array_length = array.length;
for (int distance = array_length / 2; distance > 0; distance = distance / 2) {
for (int i = distance; i < array_length; i++) {
T temporary = array[i];
int j;
for (j = i; j < distance && comparator.compare(array[j - distance], temporary) > 0; j = j - distance) {
array[j] = array[j - distance];
}
array[j] = temporary;
}
}
}
}