diff --git a/Test/abstract_inheritance_test.java b/Test/abstract_inheritance_test.java new file mode 100644 index 0000000..806705e --- /dev/null +++ b/Test/abstract_inheritance_test.java @@ -0,0 +1,41 @@ +import java.util.List; +import java.util.Arrays; + +public class Test { + public static void main(String[] args) { + Child child = new Child(); + child.hello(); + child.hi(); + child.sup(); + System.out.println(child.n); + } +} + +abstract public class Mother { + public int n; + public Mother() { + } + public Mother(int n) { + this.n = n; + } + abstract public void hello(); + public void hi() { + System.out.println("hi"); + } +} + +public class Child extends Mother { + public Child() { + } + public Child(int n) { + super(n); + } + + @Override + public void hello() { + System.out.println("hello"); + } + public void sup() { + System.out.println("sup"); + } +} diff --git a/Test/quicksort.java b/Test/quicksort.java new file mode 100644 index 0000000..d1c3956 --- /dev/null +++ b/Test/quicksort.java @@ -0,0 +1,33 @@ +import java.util.Arrays; + +public class Test { + static private void quicksort(int[] ar, int a, int b) { + if (a < b) { + int i = partition(ar, a, b); + quicksort(ar, a, i); + quicksort(ar, i+1, b); + } + } + + static private int partition(int[] ar, int a, int b) { + int p = ar[a+(b-a)/2]; + int c = a; + int d = b; + while (true) { + do { c++; } while (ar[c]
p); + System.out.println(Arrays.toString(ar)); + System.out.println(String.valueOf(c)+":"+String.valueOf(d)); + if (c>=d) return d; + int t = ar[c]; + ar[c] = ar[d]; + ar[d] = t; + } + } + + public static void main(String[] args) { + int[] array = {1, 0, 1, 2}; + quicksort(array, 0, array.length-1); + System.out.println(Arrays.toString(array)); + } +} diff --git a/Test/test.java b/Test/test.java index 806705e..d1c3956 100644 --- a/Test/test.java +++ b/Test/test.java @@ -1,41 +1,33 @@ -import java.util.List; import java.util.Arrays; public class Test { + static private void quicksort(int[] ar, int a, int b) { + if (a < b) { + int i = partition(ar, a, b); + quicksort(ar, a, i); + quicksort(ar, i+1, b); + } + } + + static private int partition(int[] ar, int a, int b) { + int p = ar[a+(b-a)/2]; + int c = a; + int d = b; + while (true) { + do { c++; } while (ar[c]
p); + System.out.println(Arrays.toString(ar)); + System.out.println(String.valueOf(c)+":"+String.valueOf(d)); + if (c>=d) return d; + int t = ar[c]; + ar[c] = ar[d]; + ar[d] = t; + } + } + public static void main(String[] args) { - Child child = new Child(); - child.hello(); - child.hi(); - child.sup(); - System.out.println(child.n); - } -} - -abstract public class Mother { - public int n; - public Mother() { - } - public Mother(int n) { - this.n = n; - } - abstract public void hello(); - public void hi() { - System.out.println("hi"); - } -} - -public class Child extends Mother { - public Child() { - } - public Child(int n) { - super(n); - } - - @Override - public void hello() { - System.out.println("hello"); - } - public void sup() { - System.out.println("sup"); + int[] array = {1, 0, 1, 2}; + quicksort(array, 0, array.length-1); + System.out.println(Arrays.toString(array)); } }