Created
January 2, 2012 23:42
-
-
Save 19h/1552653 to your computer and use it in GitHub Desktop.
Dafuq (test) + Quicksort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
class dafuq { | |
public static void crap (String v) { | |
System.out.println(v); | |
} | |
public static void main(String[] args) { | |
for ( int i = 0; i <= 200; ++i ) System.out.println("Dafuq."); | |
dafuq shit = new dafuq(); | |
crap("Fuck"); | |
System.out.println("Exiting."); | |
QS sort = new QS(); | |
int[] x = { 12, 312, 1, 123, 1122, 13, 5, 23, 6, 7 }; | |
crap(Arrays.toString(x)); | |
crap(Arrays.toString(sort.s(x))); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QS { | |
static int[] z; | |
static int n; | |
public static int[] s(int[] v) { | |
if (v ==null || v.length==0){ | |
return null; | |
} | |
z = v; | |
n = v.length; | |
qs(0, n - 1); | |
return z; | |
} | |
private static void qs(int l, int h) { | |
int i = l, j = h; | |
int p = z[l + (h-l)/2]; | |
while (i <= j) { | |
while (z[i] < p) i++; | |
while (z[j] > p) j--; | |
if (i <= j) { | |
e(i, j); | |
i++; | |
j--; | |
} | |
} | |
if (l < j) qs(l, j); | |
if (i < h) qs(i, h); | |
} | |
private static void e(int i, int j) { | |
int t = t[i]; | |
t[i] = t[j]; | |
t[j] = t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment