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 Cat | |
{ | |
private Cat() { } | |
public static void main( String[] args ) | |
{ | |
Out out = new Out( args[ args.length - 1 ] ); | |
for ( int i = 0; i < args.length - 1; i++ ) | |
{ |
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 Knuth | |
{ | |
private Knuth() { } | |
public static void shuffle( Object[] a ) | |
{ | |
int n = a.length; | |
for ( int i = 0; i < n; i++ ) | |
{ |
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.io.BufferedInputStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.URL; | |
import java.net.Socket; | |
// import java.net.HttpURLConnection; | |
import java.net.URLConnection; | |
import java.util.ArrayList; |
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.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.io.OutputStreamWriter; | |
import java.io.PrintWriter; | |
import java.net.Socket; | |
import java.util.Locale; | |
public class Out | |
{ |
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.ArrayList; | |
import java.util.InputMismatchException; | |
import java.util.Locale; | |
import java.util.NoSuchElementException; | |
import java.util.Scanner; | |
import java.util.regex.Pattern; | |
public final class StdIn | |
{ | |
private static final String CHARSET_NAME = "UTF-8"; |
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.io.OutputStreamWriter; | |
import java.io.PrintWriter; | |
import java.io.UnsupportedEncodingException; | |
import java.util.Locale; | |
public final class StdOut | |
{ | |
private static final String CHARSET_NAME = "UTF-8"; | |
private static final Locale LOCALE = Locale.US; | |
private static PrintWriter out; |
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 UF | |
{ | |
private int[] parent; // parent[i] = parent of i | |
private byte[] rank; // rank[i] = rank of subtree rooted at i (never more than 31) | |
private int count; // number of components | |
public UF( int n ) | |
{ | |
if ( n < 0 ) throw new IllegalArgumentException(); |
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 QuickUnionUF | |
{ | |
private int[] parent; // parent[i] = parent of i | |
private int count; // number of components | |
public QuickUnionUF( int n ) | |
{ | |
parent = new int[ n ]; | |
count = n; |
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 QuickFindUF | |
{ | |
private int[] id; // id[i] = component identifier of i | |
private int count; // number of components | |
public QuickFindUF( int n ) | |
{ | |
count = n; | |
id = new int[ n ]; | |
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 WeightedQuickUnionUF | |
{ | |
private int[] parent; // parent[i] = parent of i | |
private int[] size; // size[i] = number of sites in subtree rooted at i | |
private int count; // number of components | |
public WeightedQuickUnionUF( int n ) | |
{ | |
count = n; | |
parent = new int[ n ]; |