



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




2
It was the best of times next Robert Sedgewick and Kevin Wayne • Copyright © 2006 • http://www.Princeton.EDU/~cos 226
4
public interface Iterator
5 public static void main(String[] args) { Sequence
6
public interface Iterable
public static void main(String[] args) { Sequence
14
% java LoadBalance 10 0 : 1 : 2 : user 7 3 : user 1 user 2 user 8 4 : user 0 user 9 5 : 6 : user 3 user 6 7 : 8 : user 4 9 : user (^5) max load = 3 15
public class Server { private Sequence
public class LoadBalance { public static void main(String[] args) { int N = Integer.parseInt(args[ 0 ]); Server[] servers = new Server[N]; for (int i = 0 ; i < N; i++) servers[i] = new Server(); // assign N users to N servers at random for (int j = 0 ; j < N; j++) { String user = "user" + j; int i = (int) (Math.random() * N); servers[i].add(user); } // print results for (int i = 0 ; i < N; i++) System.out.println(i + ": " + servers[i]); } }
17
18
import java.util.ArrayList; public class Test { public static void main(String[] args) { ArrayList
20
public class BinaryTree