Commit 327b8737 authored by Jonas Skogtrø Olsen's avatar Jonas Skogtrø Olsen
Browse files

Initial commit

parents
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
AlgDat3
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="true" project-jdk-name="14" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/øving3.iml" filepath="$PROJECT_DIR$/øving3.iml" />
</modules>
</component>
</project>
\ No newline at end of file
import java.awt.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public class QuickSortAlgo {
private static void bubbleSort(int arr[])
{
int n = arr.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
{
// swap arr[j+1] and arr[j]
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
private static void byttPlass(int[]t,int v, int h){
int temp = t[v];
t[v] = t[h];
t[h] = temp;
}
private static int medianSort(int[]t,int v, int h){
int m = (v+h)/2;
if(t[v]>t[m])byttPlass(t,v,m);
if(t[m]>t[h]){
byttPlass(t,m,h);
if(t[v]>t[m])byttPlass(t,v,m);
}
return m;
}
private static int splitt(int[]t,int v ,int h){
int iv, ih;
int m = medianSort(t,v,h);
int dv = t[m];
byttPlass(t,m,h-1);
for(iv=v,ih=h-1;;){
while(t[++iv]<dv);
while(t[--ih]>dv);
if(iv>=ih)break;
byttPlass(t,iv,ih);
}
byttPlass(t,iv,h-1);
return iv;
}
public static void quicksort(int[]t,int v, int h){
if(h-v>2){
int delpos = splitt(t,v,h);
quicksort(t,v,delpos-1);
quicksort(t,delpos+1,h);
}else {
medianSort(t,v,h);
}
}
public static void quicksortBubble(int[]t,int v, int h){
//#TODO finn ut hva" h-v > ?" best for spørsmålstegnet
if(h-v>t.length/2){
int delpos = splitt(t,v,h);
quicksort(t,v,delpos-1);
quicksort(t,delpos+1,h);
}else {
bubbleSort(t);
}
}
public static void main(String[]args){
//#todo lage liste med 100000 tall
//#TODO ta tid bå begge funksjonene
//#TODo lage sjekksum og korekthetstest
int liste[] ={5,6,7,8,22,12,1,24,36,347,3,7,36,73,4,234,5,3657,2,45,4};
System.out.println(Arrays.toString(liste));
bubbleSort(liste);
//quicksortBubble(liste,0,n-1);
System.out.println(Arrays.toString(liste));
}
}
<?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>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment