mirror of
https://github.com/ossu/computer-science.git
synced 2025-04-18 06:35:58 -04:00
insertion sort wrong
This commit is contained in:
parent
4ec587f5b7
commit
6c24908481
@ -0,0 +1 @@
|
||||
/.metadata/
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
@ -0,0 +1 @@
|
||||
/bin/
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>InsertionSort</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
@ -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
|
@ -0,0 +1,19 @@
|
||||
package InsertionSort;
|
||||
|
||||
public class InsertionSort {
|
||||
public int[] sort(int[] arr) {
|
||||
for (int limiter=1; limiter < arr.length; limiter++) {
|
||||
int i = 1;
|
||||
int j = limiter;
|
||||
int border = arr[limiter];
|
||||
while (limiter>=i && border < arr[limiter-i]) {
|
||||
arr[j] = arr[j-1];
|
||||
arr[j-1] = border;
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package InsertionSort;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
|
||||
|
||||
//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 static void main(String[] args) {
|
||||
int[] toSort = new int[] {4, 5, 9, 3, 54, 2, 34, 2134, 2, 443, 23, 12, 4, 663, 123, 42};
|
||||
InsertionSort sorter = new InsertionSort();
|
||||
int[] sorted = sorter.sort(toSort);
|
||||
System.out.println(Arrays.toString(sorted));
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
module InsertionSort {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user