Skip to content
Snippets Groups Projects
Commit 72e83c0a authored by Lawrence Chung's avatar Lawrence Chung
Browse files

Merge branch 'TeamB' of https://gitlab.cas.mcmaster.ca/schankuc/2XB3 into TeamB

parents dbe45f0c 2938d63b
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,9 @@ package search;
public class GraphBuild {
private final int V;
private int E;
private Fish<Integer>[] adj;
private final int V; // Number of nodes
private int E; // Number of edges
private Fish<Integer>[] adj; // Adjacency list for a node
public static void main(String[] args) {
......
package sort;
// Code from "Algorithms: 4th Edition" by Robert Sedgewick
// Adapted from the Sedgewick Quicksort implementation
public class QuickSelect {
private static int median;
private static int count;
public static void sort(Comparable[] a) {
//StdRandom.shuffle(a); // Eliminate dependence on input
median = a.length/2;
sort(a, 0, a.length - 1);
}
private static void sort(Comparable[] a, int lo, int hi) {
if (hi <= lo)
return;
int j = partition(a, lo, hi);
if (j < median)
sort(a, j + 1, hi); // Sort right part a[j+1 .. hi].
else if (j > median)
sort(a, lo, j - 1); // Sort left part a[lo .. j-1].
return;
}
private static int partition(Comparable[] a, int lo, int hi) {
// Partition into a[lo..i-1], a[i], a[i+1..hi].
int i = lo, j = hi + 1; // left and right scan indices
Comparable v = a[lo]; // partitioning item
while (true) { // Scan right, scan left, check for scan complete, and exchange.
while (less(a[++i], v))
if (i == hi)
break;
while (less(v, a[--j]))
if (j == lo)
break;
if (i >= j)
break;
exch(a, i, j);
}
exch(a, lo, j);
return j;
}
private static void exch(Comparable[] a, int b, int c) {
Comparable temp = a[c];
a[c] = a[b];
a[b] = temp;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment