From 4ec587f5b7e12eeb3fdf21a227b04172b4493536 Mon Sep 17 00:00:00 2001 From: Reborn Date: Wed, 19 Mar 2025 12:07:54 +0000 Subject: [PATCH] Selection sort implementation --- .../SelectionSort/.gitignore | 1 + .../SelectionSort/SelectionSort/.classpath | 10 +++++++++ .../SelectionSort/SelectionSort/.gitignore | 1 + .../SelectionSort/SelectionSort/.project | 17 +++++++++++++++ .../org.eclipse.core.resources.prefs | 2 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++++++++++ .../SelectionSort/src/SelectionSort/Main.java | 15 +++++++++++++ .../src/SelectionSort/SelectionSort.java | 21 +++++++++++++++++++ .../SelectionSort/src/module-info.java | 8 +++++++ 9 files changed, 86 insertions(+) create mode 100644 Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/.gitignore create mode 100644 Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.classpath create mode 100644 Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.gitignore create mode 100644 Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.project create mode 100644 Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.settings/org.eclipse.core.resources.prefs create mode 100644 Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.settings/org.eclipse.jdt.core.prefs create mode 100644 Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/src/SelectionSort/Main.java create mode 100644 Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/src/SelectionSort/SelectionSort.java create mode 100644 Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/src/module-info.java diff --git a/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/.gitignore b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/.gitignore new file mode 100644 index 0000000..e10e727 --- /dev/null +++ b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/.gitignore @@ -0,0 +1 @@ +/.metadata/ diff --git a/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.classpath b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.classpath new file mode 100644 index 0000000..57bca72 --- /dev/null +++ b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.gitignore b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.project b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.project new file mode 100644 index 0000000..3093c95 --- /dev/null +++ b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.project @@ -0,0 +1,17 @@ + + + SelectionSort + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.settings/org.eclipse.core.resources.prefs b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.settings/org.eclipse.jdt.core.prefs b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3d1fdb6 --- /dev/null +++ b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/src/SelectionSort/Main.java b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/src/SelectionSort/Main.java new file mode 100644 index 0000000..62a2485 --- /dev/null +++ b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/src/SelectionSort/Main.java @@ -0,0 +1,15 @@ +package SelectionSort; + +import java.util.Arrays; + +//Selection sort is the algorithm to sort one spot at a time +//Comb the entire array, select the smallest and place it at the beginning +public class Main +{ + public static void main(String[] args) { + int[] toSort = new int[] {1, 5, 9, 3, 54, 2, 34, 2134, 2, 443, 23, 12, 4, 663, 123, 42}; + SelectionSort sorter = new SelectionSort(); + int[] sorted = sorter.sort(toSort); + System.out.println(Arrays.toString(sorted)); + } +} \ No newline at end of file diff --git a/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/src/SelectionSort/SelectionSort.java b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/src/SelectionSort/SelectionSort.java new file mode 100644 index 0000000..d792726 --- /dev/null +++ b/Course Activities/02 - Core CS/05 - Core theory/01 - Divide and Conquer, Sorting and Searching, and Randomized Algorithm/SelectionSort/SelectionSort/src/SelectionSort/SelectionSort.java @@ -0,0 +1,21 @@ +package SelectionSort; + +public class SelectionSort { + public int[] sort(int[] arr) { + for (int i=0; i