├── exercises ├── DIY │ ├── inheritance1 │ │ ├── AList.java │ │ ├── IsADemo.java │ │ ├── SLList.java │ │ └── WordUtils.java │ ├── inheritance2 │ │ ├── List61B.java │ │ ├── RotatingSLList.java │ │ ├── SLList.java │ │ └── VengefulSLList.java │ ├── inheritance3 │ │ ├── Comparator.java │ │ ├── Dog.java │ │ ├── DogLauncher.java │ │ └── Maximizer.java │ ├── inheritance4 │ │ └── ArraySet.java │ ├── readme │ ├── syntax1 │ │ ├── ArrayMap.java │ │ ├── Map61B.java │ │ └── MapHelper.java │ └── syntax3 │ │ ├── accessControl │ │ ├── hw1Skeleton │ │ │ └── synthesizer │ │ │ │ ├── ArrayRingBuffer.java.skeleton │ │ │ │ └── GuitarString.java.skeleton │ │ ├── illuminati │ │ │ └── ChattyMap.java │ │ └── syntax3 │ │ │ └── map │ │ │ ├── ArrayMap.java │ │ │ ├── ExceptionDemo.java │ │ │ ├── IterationDemo.java │ │ │ ├── Map61B.java │ │ │ ├── MapHelper.java │ │ │ └── MyonicArrayMap.java │ │ └── objectMethods │ │ └── objectMethods │ │ ├── Date.java │ │ └── DateEqualsTest.java ├── lists1 │ ├── IntList.class │ ├── IntList.java │ ├── Lists1Exercises.class │ └── Lists1Exercises.java └── lists4 │ ├── AList.java │ └── AListTest.java ├── inheritance1 ├── AList.java ├── IsADemo.java ├── List61B.java ├── SLList.java └── WordUtils.java ├── inheritance2 ├── HoFDemo.java ├── IntUnaryFunction.java ├── List61B.java ├── RotatingSLList.java ├── SLList.java ├── TenX.java └── VengefulSLList.java ├── inheritance3 ├── Comparator.java ├── Dog.java ├── DogLauncher.java └── Maximizer.java ├── inheritance4 └── ArraySet.java ├── intro1 ├── HelloNumbers.java ├── HelloWorld.java ├── LargerDemo.java ├── hello.py ├── hellonumbers.py └── larger.py ├── intro2 ├── ArgsDemo.java ├── ArgsSum.java ├── Dog.java ├── DogLauncher.java └── HelloWorld.java ├── library ├── hamcrest-core-1.3.jar └── junit-4.12.jar ├── lists1 └── IntList.java ├── lists2 ├── IntList.java ├── IntNode.java └── SLList.java ├── lists3 ├── ArrayBasics.java ├── ArrayBasics2.java ├── ArrayDanger.java ├── ArraysBasics2.java ├── SLList.java └── SLListLauncher.java ├── lists4 ├── AList.java ├── AListTest.java └── speedtest │ ├── AList.java │ ├── SLList.java │ ├── SpeedTestAList.java │ └── SpeedTestSLList.java └── testing ├── .idea ├── libraries │ └── library.xml ├── misc.xml ├── modules.xml └── workspace.xml ├── Sort.java ├── TestSort.java ├── out └── production │ └── testing │ ├── .idea │ ├── libraries │ │ └── library.xml │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml │ ├── Sort.class │ ├── TestSort.class │ └── testing.iml └── testing.iml /exercises/DIY/inheritance1/AList.java: -------------------------------------------------------------------------------- 1 | /** Array based list. 2 | * @author Josh Hug 3 | */ 4 | 5 | // 0 1 2 3 4 5 6 7 6 | // items: [6 9 -1 2 0 0 0 0 ...] 7 | // size: 5 8 | 9 | /* Invariants: 10 | addLast: The next item we want to add, will go into position size 11 | getLast: The item we want to return is in position size - 1 12 | size: The number of items in the list should be size. 13 | */ 14 | 15 | public class AList { 16 | private Item[] items; 17 | private int size; 18 | 19 | /** Creates an empty list. */ 20 | public AList() { 21 | items = (Item[]) new Object[100]; 22 | size = 0; 23 | } 24 | 25 | /** Inserts item into given position. 26 | * Code from discussion #3 */ 27 | public void insert(Item x, int position) { 28 | Item[] newItems = (Item[]) new Object[items.length + 1]; 29 | 30 | System.arraycopy(items, 0, newItems, 0, position); 31 | newItems[position] = x; 32 | 33 | System.arraycopy(items, position, newItems, position + 1, items.length - position); 34 | items = newItems; 35 | } 36 | 37 | /** Resizes the underlying array to the target capacity. */ 38 | private void resize(int capacity) { 39 | Item[] a = (Item[]) new Object[capacity]; 40 | System.arraycopy(items, 0, a, 0, size); 41 | items = a; 42 | } 43 | 44 | /** Inserts an item at the front. */ 45 | public void addFirst(Item x) { 46 | insert(x, 0); 47 | } 48 | 49 | /** Inserts X into the back of the list. */ 50 | public void addLast(Item x) { 51 | if (size == items.length) { 52 | resize(size + 1); 53 | } 54 | 55 | items[size] = x; 56 | size = size + 1; 57 | } 58 | 59 | /** Gets an item from the front. */ 60 | public Item getFirst() { 61 | return get(0); 62 | } 63 | 64 | /** Returns the item from the back of the list. */ 65 | public Item getLast() { 66 | return items[size - 1]; 67 | } 68 | /** Gets the ith item in the list (0 is the front). */ 69 | public Item get(int i) { 70 | return items[i]; 71 | } 72 | 73 | /** Returns the number of items in the list. */ 74 | public int size() { 75 | return size; 76 | } 77 | 78 | /** Deletes item from back of the list and 79 | * returns deleted item. */ 80 | public Item removeLast() { 81 | Item x = getLast(); 82 | items[size - 1] = null; 83 | size = size - 1; 84 | return x; 85 | } 86 | } -------------------------------------------------------------------------------- /exercises/DIY/inheritance1/IsADemo.java: -------------------------------------------------------------------------------- 1 | public class IsADemo { 2 | public static void main(String[] args) { 3 | /*List61B someList = new SLList<>(); 4 | someList.addFirst("elk"); 5 | someList.addLast("dwell"); 6 | someList.addLast("on"); 7 | someList.addLast("existential"); 8 | someList.addLast("crises"); 9 | someList.print();*/ 10 | } 11 | } -------------------------------------------------------------------------------- /exercises/DIY/inheritance1/SLList.java: -------------------------------------------------------------------------------- 1 | /** An SLList is a list of integers, which hides the terrible truth 2 | * of the nakedness within. */ 3 | public class SLList { 4 | private class Node { 5 | public Blorp item; 6 | public Node next; 7 | 8 | public Node(Blorp i, Node n) { 9 | item = i; 10 | next = n; 11 | } 12 | } 13 | 14 | /* The first item (if it exists) is at sentinel.next. */ 15 | private Node sentinel; 16 | private int size; 17 | 18 | /** Creates an empty SLList. */ 19 | public SLList() { 20 | sentinel = new Node(null, null); 21 | size = 0; 22 | } 23 | 24 | public SLList(Blorp x) { 25 | sentinel = new Node(null, null); 26 | sentinel.next = new Node(x, null); 27 | size = 1; 28 | } 29 | 30 | /** Inserts the item into the given position in 31 | * the list. If position is greater than the 32 | * size of the list, inserts at the end instead. 33 | */ 34 | public void insert(Blorp item, int position) { 35 | Node p = sentinel; 36 | while (position > 1 && p.next != null) { 37 | position--; 38 | p = p.next; 39 | } 40 | Node newNode = new Node(item, p.next); 41 | p.next = newNode; 42 | } 43 | 44 | /** Adds x to the front of the list. */ 45 | public void addFirst(Blorp x) { 46 | sentinel.next = new Node(x, sentinel.next); 47 | size = size + 1; 48 | } 49 | 50 | /** Adds x to the end of the list. */ 51 | public void addLast(Blorp x) { 52 | size = size + 1; 53 | 54 | Node p = sentinel; 55 | 56 | /* Advance p to the end of the list. */ 57 | while (p.next != null) { 58 | p = p.next; 59 | } 60 | 61 | p.next = new Node(x, null); 62 | } 63 | 64 | /** Returns the first item in the list. */ 65 | public Blorp getFirst() { 66 | return sentinel.next.item; 67 | } 68 | 69 | /** Returns the back node of our list. */ 70 | private Node getLastNode() { 71 | Node p = sentinel; 72 | 73 | /* Move p until it reaches the end. */ 74 | while (p.next != null) { 75 | p = p.next; 76 | } 77 | return p; 78 | } 79 | 80 | /** Returns last item */ 81 | public Blorp getLast() { 82 | Node back = getLastNode(); 83 | return back.item; 84 | } 85 | 86 | /** Returns the ith item in the list. */ 87 | public Blorp get(int i) { 88 | return get(i, sentinel.next); 89 | } 90 | 91 | private Blorp get(int i, Node p) { 92 | if (i == 0) { 93 | return p.item; 94 | } 95 | return get(i - 1, p.next); 96 | } 97 | 98 | /** Returns the size of the list. */ 99 | public int size() { 100 | return size; 101 | } 102 | 103 | /** Deletes and returns last item. */ 104 | public Blorp removeLast() { 105 | Node back = getLastNode(); 106 | if (back == sentinel) { 107 | return null; 108 | } 109 | 110 | Node p = sentinel; 111 | 112 | while (p.next != back) { 113 | p = p.next; 114 | } 115 | p.next = null; 116 | return back.item; 117 | } 118 | 119 | public static void main(String[] args) { 120 | /* Creates a list of one integer, namely 10 */ 121 | SLList L = new SLList(); 122 | L.addLast(20); 123 | System.out.println(L.size()); 124 | } 125 | } -------------------------------------------------------------------------------- /exercises/DIY/inheritance1/WordUtils.java: -------------------------------------------------------------------------------- 1 | public class WordUtils { 2 | /** Returns the length of the longest word. */ 3 | public static String longest(SLList list) { 4 | int maxDex = 0; 5 | for (int i = 0; i < list.size(); i += 1) { 6 | String longestString = list.get(maxDex); 7 | String thisString = list.get(i); 8 | if (thisString.length() > longestString.length()) { 9 | maxDex = i; 10 | } 11 | } 12 | return list.get(maxDex); 13 | } 14 | 15 | public static void main(String[] args) { 16 | SLList someList = new SLList<>(); 17 | someList.addLast("elk"); 18 | someList.addLast("are"); 19 | someList.addLast("watching"); 20 | System.out.println(longest(someList)); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /exercises/DIY/inheritance2/List61B.java: -------------------------------------------------------------------------------- 1 | public interface List61B { 2 | /** 3 | * Inserts X into the back of the list. 4 | */ 5 | public void addLast(Item x); 6 | 7 | /** 8 | * Returns the item from the back of the list. 9 | */ 10 | public Item getLast(); 11 | 12 | /** 13 | * Gets the ith item in the list (0 is the front). 14 | */ 15 | public Item get(int i); 16 | 17 | /** 18 | * Returns the number of items in the list. 19 | */ 20 | public int size(); 21 | 22 | /** 23 | * Deletes item from back of the list and 24 | * returns deleted item. 25 | */ 26 | public Item removeLast(); 27 | 28 | /** 29 | * Inserts item into given position. 30 | * Code from discussion #3 31 | */ 32 | public void insert(Item x, int position); 33 | 34 | /** 35 | * Inserts an item at the front. 36 | */ 37 | public void addFirst(Item x); 38 | 39 | /** 40 | * Gets an item from the front. 41 | */ 42 | public Item getFirst(); 43 | 44 | /** Prints the list. Works for ANY kind of list. */ 45 | default public void print() { 46 | for (int i = 0; i < size(); i = i + 1) { 47 | System.out.print(get(i) + " "); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /exercises/DIY/inheritance2/RotatingSLList.java: -------------------------------------------------------------------------------- 1 | /* SLList, but with additional rotateRight operation. */ 2 | public class RotatingSLList extends SLList{ 3 | /** To do: Implement RotatingSLList such that code compiles and outputs correct result. */ 4 | 5 | public static void main(String[] args) { 6 | RotatingSLList rsl = new RotatingSLList<>(); 7 | /* Creates SList: [10, 11, 12, 13] */ 8 | rsl.addLast(10); 9 | rsl.addLast(11); 10 | rsl.addLast(12); 11 | rsl.addLast(13); 12 | 13 | /* Should be: [13, 10, 11, 12] */ 14 | rsl.rotateRight(); 15 | rsl.print(); 16 | } 17 | } -------------------------------------------------------------------------------- /exercises/DIY/inheritance2/SLList.java: -------------------------------------------------------------------------------- 1 | /* Represent a list of stuff, where all the "list" work is delegated 2 | * to a naked recursive data structure. */ 3 | 4 | public class SLList implements List61B { 5 | public class Node { 6 | public Blorp item; /* Equivalent of first */ 7 | public Node next; /* Equivalent of rest */ 8 | 9 | public Node(Blorp i, Node h) { 10 | item = i; 11 | next = h; 12 | } 13 | } 14 | 15 | private Node sentinel; 16 | private int size; 17 | 18 | /** Creates an empty list. */ 19 | public SLList() { 20 | size = 0; 21 | sentinel = new Node(null, null); 22 | } 23 | 24 | public SLList(Blorp x) { 25 | size = 1; 26 | sentinel = new Node(null, null); 27 | sentinel.next = new Node(x, null); 28 | } 29 | 30 | /** Adds an item of the front. */ 31 | public void addFirst(Blorp x) { 32 | Node oldFrontNode = sentinel.next; 33 | Node newNode = new Node(x, oldFrontNode); 34 | sentinel.next = newNode; 35 | size += 1; 36 | } 37 | 38 | /** Gets the front item of the list. */ 39 | public Blorp getFirst() { 40 | return sentinel.next.item; 41 | } 42 | 43 | /** Puts an item at the back of the list. */ 44 | public void addLast(Blorp x) { 45 | size += 1; 46 | 47 | Node p = sentinel; 48 | 49 | /* Move p until it reaches the end. */ 50 | while (p.next != null) { 51 | p = p.next; 52 | } 53 | 54 | p.next = new Node(x, null); 55 | } 56 | 57 | /** Returns the back node of our list. */ 58 | private Node getLastNode() { 59 | Node p = sentinel; 60 | 61 | /* Move p until it reaches the end. */ 62 | while (p.next != null) { 63 | p = p.next; 64 | } 65 | return p; 66 | } 67 | 68 | /** Returns last item */ 69 | public Blorp getLast() { 70 | Node back = getLastNode(); 71 | return back.item; 72 | } 73 | 74 | /** Deletes and returns last item. */ 75 | public Blorp removeLast() { 76 | Node back = getLastNode(); 77 | if (back == sentinel) { 78 | return null; 79 | } 80 | 81 | Node p = sentinel; 82 | 83 | while (p.next != back) { 84 | p = p.next; 85 | } 86 | p.next = null; 87 | return back.item; 88 | } 89 | 90 | public int size() { 91 | return size; 92 | } 93 | 94 | /** Gets the positionth item of the list. */ 95 | public Blorp get(int position) { 96 | if (position == 0) { 97 | return getFirst(); 98 | } 99 | Node currentNode = sentinel.next.next; 100 | while (position > 1 && currentNode.next != null) { 101 | position -= 1; 102 | currentNode = currentNode.next; 103 | } 104 | 105 | return currentNode.item; 106 | } 107 | 108 | /** Inserts item into given position. 109 | * Code from discussion #3 */ 110 | public void insert(Blorp item, int position) { 111 | if (sentinel.next == null || position == 0) { 112 | addFirst(item); 113 | return; 114 | } 115 | 116 | Node currentNode = sentinel.next.next; 117 | while (position > 1 && currentNode.next != null) { 118 | position -= 1; 119 | currentNode = currentNode.next; 120 | } 121 | 122 | Node newNode = new Node(item, currentNode.next); 123 | currentNode.next = newNode; 124 | } 125 | 126 | 127 | /** TODO: Add a print method that overrides List61B's inefficient print method. */ 128 | @Override 129 | public void print() { 130 | for (Node p = sentinel.next; p != null; p = p.next) { 131 | System.out.print(p.item + " "); 132 | } 133 | } 134 | } -------------------------------------------------------------------------------- /exercises/DIY/inheritance2/VengefulSLList.java: -------------------------------------------------------------------------------- 1 | /** SList with additional operation printLostItems() which prints all items 2 | * that have ever been deleted. */ 3 | public class VengefulSLList { 4 | public static void main(String[] args) { 5 | /* 6 | VengefulSLList vs1 = new VengefulSLList(); 7 | vs1.addLast(1); 8 | vs1.addLast(5); 9 | vs1.addLast(10); 10 | vs1.addLast(13); 11 | // vs1 is now: [1, 5, 10, 13] 12 | 13 | vs1.removeLast(); 14 | vs1.removeLast(); 15 | // After deletion, vs1 is: [1, 5] 16 | 17 | // Should print out the numbers of the fallen, namely 10 and 13. 18 | System.out.print("The fallen are: "); 19 | vs1.printLostItems(); */ 20 | } 21 | } -------------------------------------------------------------------------------- /exercises/DIY/inheritance3/Comparator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by jug on 2/7/18. 3 | */ 4 | public interface Comparator { 5 | public int compare(T x1, T x2); 6 | } 7 | -------------------------------------------------------------------------------- /exercises/DIY/inheritance3/Dog.java: -------------------------------------------------------------------------------- 1 | public class Dog implements Comparable { 2 | public String name; 3 | private int size; 4 | 5 | public Dog(String n, int s) { 6 | name = n; 7 | size = s; 8 | } 9 | 10 | @Override 11 | public int compareTo(Dog uddaDog) { 12 | //assume nobody is messing up and giving us 13 | //something that isn't a dog. 14 | return size - uddaDog.size; 15 | } 16 | 17 | 18 | 19 | public void bark() { 20 | System.out.println(name + " says: bark"); 21 | } 22 | } -------------------------------------------------------------------------------- /exercises/DIY/inheritance3/DogLauncher.java: -------------------------------------------------------------------------------- 1 | public class DogLauncher { 2 | public static void main(String[] args) { 3 | Dog d1 = new Dog("Elyse", 3); 4 | Dog d2 = new Dog("Sture", 9); 5 | Dog d3 = new Dog("Benjamin", 15); 6 | Dog[] dogs = new Dog[]{d1, d2, d3}; 7 | 8 | Dog d = (Dog) Maximizer.max(dogs); 9 | System.out.println(d.name); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /exercises/DIY/inheritance3/Maximizer.java: -------------------------------------------------------------------------------- 1 | public class Maximizer { 2 | public static Comparable max(Comparable[] items) { 3 | int maxDex = 0; 4 | for (int i = 0; i < items.length; i += 1) { 5 | int cmp = items[i].compareTo(items[maxDex]); 6 | 7 | if (cmp > 0) { 8 | maxDex = i; 9 | } 10 | } 11 | return items[maxDex]; 12 | } 13 | } -------------------------------------------------------------------------------- /exercises/DIY/inheritance4/ArraySet.java: -------------------------------------------------------------------------------- 1 | public class ArraySet { 2 | 3 | public ArraySet() { 4 | } 5 | 6 | /* Returns true if this map contains a mapping for the specified key. 7 | */ 8 | public boolean contains(T x) { 9 | return false; 10 | } 11 | 12 | /* Associates the specified value with the specified key in this map. 13 | Throws an IllegalArgumentException if the key is null. */ 14 | public void add(T x) { 15 | return; 16 | } 17 | 18 | /* Returns the number of key-value mappings in this map. */ 19 | public int size() { 20 | return 0; 21 | } 22 | 23 | public static void main(String[] args) { 24 | ArraySet s = new ArraySet<>(); 25 | s.add(null); 26 | s.add("horse"); 27 | s.add("fish"); 28 | s.add("house"); 29 | s.add("fish"); 30 | System.out.println(s.contains("horse")); 31 | System.out.println(s.size()); 32 | } 33 | 34 | /* Also to do: 35 | 1. Make ArraySet implement the Iterable interface. 36 | 2. Implement a toString method. 37 | 3. Implement an equals() method. 38 | */ 39 | } 40 | -------------------------------------------------------------------------------- /exercises/DIY/readme: -------------------------------------------------------------------------------- 1 | This directory contains the starter code that I use for every lecture, starting from lecture 8. Seems like this might be handy for those of you who want to try and reimplement things just like I did. Theoretically, you could even use it to present your own lecture on each topic. 2 | -------------------------------------------------------------------------------- /exercises/DIY/syntax1/ArrayMap.java: -------------------------------------------------------------------------------- 1 | package Map61B; 2 | 3 | import org.junit.Assert.*; 4 | import java.util.List; 5 | import java.util.ArrayList; 6 | import org.junit.Test; 7 | 8 | 9 | import static org.junit.Assert.*; 10 | 11 | /** 12 | * An array based implementation of the Map61B class. 13 | */ 14 | public class ArrayMap implements Map61B { 15 | public ArrayMap() { 16 | } 17 | 18 | /** Returns the index of the given key if it exists, 19 | * -1 otherwise. */ 20 | private int keyIndex(K key) { 21 | return 0; 22 | } 23 | 24 | 25 | public boolean containsKey(K key) { 26 | return false; 27 | } 28 | 29 | public void put(K key, V value) { 30 | 31 | } 32 | 33 | public V get(K key) { 34 | return false; 35 | } 36 | 37 | public int size() { 38 | return 0; 39 | } 40 | 41 | public List keys() { 42 | return null; 43 | } 44 | 45 | /*@Test 46 | public void test() { 47 | ArrayMap am = new ArrayMap(); 48 | am.put(2, 5); 49 | int expected = 5; 50 | assertEquals(expected, am.get(2)); 51 | }*/ 52 | 53 | public static void main(String[] args) { 54 | ArrayMap m = new ArrayMap(); 55 | m.put("horse", 3); 56 | m.put("fish", 9); 57 | m.put("house", 10); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /exercises/DIY/syntax1/Map61B.java: -------------------------------------------------------------------------------- 1 | package Map61B; 2 | import java.util.List; 3 | 4 | public interface Map61B { 5 | /* Returns true if this map contains a mapping for the specified key. */ 6 | boolean containsKey(K key); 7 | 8 | /* Returns the value to which the specified key is mapped. No defined 9 | * behavior if the key doesn't exist (ok to crash). */ 10 | V get(K key); 11 | 12 | /* Returns the number of key-value mappings in this map. */ 13 | int size(); 14 | 15 | /* Associates the specified value with the specified key in this map. */ 16 | void put(K key, V value); 17 | 18 | /* Returns a list of the keys in this map. */ 19 | List keys(); 20 | } -------------------------------------------------------------------------------- /exercises/DIY/syntax1/MapHelper.java: -------------------------------------------------------------------------------- 1 | package Map61B; 2 | 3 | import static org.junit.Assert.*; 4 | import org.junit.Test; 5 | import java.util.List; 6 | 7 | /** 8 | * Class to demonstrate how generic methods work in Java. 9 | */ 10 | public class MapHelper { 11 | /* Write the following three methods: 12 | /* get(Key) : Return item in map if it exists. */ 13 | /* maxKey() : Returns max of all keys. Works only if x and y have comparable data. */ 14 | /* allBark(): Makes all keys bark, but only works for Dogs. */ 15 | 16 | @Test 17 | public void testGet() { 18 | Map61B m = new ArrayMap(); 19 | m.put("horse", 3); 20 | m.put("fish", 9); 21 | m.put("house", 10); 22 | 23 | /*Integer actual = MapHelper.get(m, "fish"); 24 | Integer expected = 9; 25 | assertEquals(expected, actual);*/ 26 | } 27 | 28 | @Test 29 | public void testMaxKey() { 30 | Map61B m = new ArrayMap(); 31 | m.put("horse", 3); 32 | m.put("fish", 9); 33 | m.put("house", 10); 34 | 35 | /*String actual = MapHelper.maxKey(m); 36 | String expected = "house"; 37 | assertEquals(expected, actual);*/ 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /exercises/DIY/syntax3/accessControl/hw1Skeleton/synthesizer/ArrayRingBuffer.java.skeleton: -------------------------------------------------------------------------------- 1 | // TODO: Make sure to make this class a part of the synthesizer package 2 | // package ; 3 | import java.util.Iterator; 4 | 5 | //TODO: Make sure to make this class and all of its methods public 6 | //TODO: Make sure to make this class extend AbstractBoundedQueue 7 | public class ArrayRingBuffer { 8 | /* Index for the next dequeue or peek. */ 9 | private int first; // index for the next dequeue or peek 10 | /* Index for the next enqueue. */ 11 | private int last; 12 | /* Array for storing the buffer data. */ 13 | private T[] rb; 14 | 15 | /** 16 | * Create a new ArrayRingBuffer with the given capacity. 17 | */ 18 | public ArrayRingBuffer(int capacity) { 19 | // TODO: Create new array with capacity elements. 20 | // first, last, and fillCount should all be set to 0. 21 | // this.capacity should be set appropriately. Note that the local variable 22 | // here shadows the field we inherit from AbstractBoundedQueue, so 23 | // you'll need to use this.capacity to set the capacity. 24 | } 25 | 26 | /** 27 | * Adds x to the end of the ring buffer. If there is no room, then 28 | * throw new RuntimeException("Ring buffer overflow"). Exceptions 29 | * covered Monday. 30 | */ 31 | public void enqueue(T x) { 32 | // TODO: Enqueue the item. Don't forget to increase fillCount and update last. 33 | } 34 | 35 | /** 36 | * Dequeue oldest item in the ring buffer. If the buffer is empty, then 37 | * throw new RuntimeException("Ring buffer underflow"). Exceptions 38 | * covered Monday. 39 | */ 40 | public T dequeue() { 41 | // TODO: Dequeue the first item. Don't forget to decrease fillCount and update 42 | } 43 | 44 | /** 45 | * Return oldest item, but don't remove it. 46 | */ 47 | public T peek() { 48 | // TODO: Return the first item. None of your instance variables should change. 49 | } 50 | 51 | // TODO: When you get to part 5, implement the needed code to support iteration. 52 | } 53 | -------------------------------------------------------------------------------- /exercises/DIY/syntax3/accessControl/hw1Skeleton/synthesizer/GuitarString.java.skeleton: -------------------------------------------------------------------------------- 1 | // TODO: Make sure to make this class a part of the synthesizer package 2 | //package ; 3 | 4 | //Make sure this class is public 5 | public class GuitarString { 6 | /** Constants. Do not change. In case you're curious, the keyword final means 7 | * the values cannot be changed at runtime. We'll discuss this and other topics 8 | * in lecture on Friday. */ 9 | private static final int SR = 44100; // Sampling Rate 10 | private static final double DECAY = .996; // energy decay factor 11 | 12 | /* Buffer for storing sound data. */ 13 | private BoundedQueue buffer; 14 | 15 | /* Create a guitar string of the given frequency. */ 16 | public GuitarString(double frequency) { 17 | // TODO: Create a buffer with capacity = SR / frequency. You'll need to 18 | // cast the result of this division operation into an int. For better 19 | // accuracy, use the Math.round() function before casting. 20 | // Your buffer should be initially filled with zeros. 21 | } 22 | 23 | 24 | /* Pluck the guitar string by replacing the buffer with white noise. */ 25 | public void pluck() { 26 | // TODO: Dequeue everything in the buffer, and replace it with random numbers 27 | // between -0.5 and 0.5. You can get such a number by using: 28 | // double r = Math.random() - 0.5; 29 | // 30 | // Make sure that your random numbers are different from each other. 31 | } 32 | 33 | /* Advance the simulation one time step by performing one iteration of 34 | * the Karplus-Strong algorithm. 35 | */ 36 | public void tic() { 37 | // TODO: Dequeue the front sample and enqueue a new sample that is 38 | // the average of the two multiplied by the DECAY factor. 39 | // Do not call StdAudio.play(). 40 | } 41 | 42 | /* Return the double at the front of the buffer. */ 43 | public double sample() { 44 | // TODO: Return the correct thing. 45 | return 0; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /exercises/DIY/syntax3/accessControl/illuminati/ChattyMap.java: -------------------------------------------------------------------------------- 1 | package illuminati; 2 | import syntax3.map.ArrayMap; 3 | 4 | /** 5 | * Created by hug. 6 | */ 7 | public class ChattyMap extends ArrayMap { 8 | public static void printSize() { 9 | //System.out.println(size); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /exercises/DIY/syntax3/accessControl/syntax3/map/ArrayMap.java: -------------------------------------------------------------------------------- 1 | package syntax3.map; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | 6 | import org.junit.Test; 7 | import java.util.Iterator; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | /** 12 | * An array based implementation of the Map61B class. 13 | */ 14 | public class ArrayMap implements Map61B, Iterable { 15 | private K[] keys; 16 | private V[] values; 17 | int size; 18 | 19 | public ArrayMap() { 20 | keys = (K[]) new Object[100]; 21 | values = (V[]) new Object[100]; 22 | size = 0; 23 | } 24 | 25 | public Iterator iterator() { 26 | return new KeyIterator(); 27 | } 28 | 29 | private class KeyIterator implements Iterator { 30 | private int wizardPosition; 31 | 32 | public KeyIterator() { 33 | wizardPosition = 0; 34 | } 35 | 36 | public boolean hasNext() { 37 | return wizardPosition < size; 38 | } 39 | 40 | public K next() { 41 | K returnVal = keys[wizardPosition]; 42 | wizardPosition += 1; 43 | return returnVal; 44 | } 45 | } 46 | 47 | /** 48 | * Returns the index of the given key if it exists, 49 | * -1 otherwise. 50 | */ 51 | private int keyIndex(K key) { 52 | for (int i = 0; i < size; i += 1) { 53 | if (keys[i].equals(key)) { 54 | return i; 55 | } 56 | } 57 | return -1; 58 | } 59 | 60 | public boolean containsKey(K key) { 61 | int index = keyIndex(key); 62 | return index > -1; 63 | } 64 | 65 | public void put(K key, V value) { 66 | int index = keyIndex(key); 67 | if (index == -1) { 68 | keys[size] = key; 69 | values[size] = value; 70 | size += 1; 71 | return; 72 | } 73 | values[index] = value; 74 | } 75 | 76 | public V get(K key) { 77 | int index = keyIndex(key); 78 | if (index == -1) { 79 | throw new IllegalArgumentException("The key provided " + key + " was not in ArrayMap."); 80 | } 81 | return values[index]; 82 | } 83 | 84 | public int size() { 85 | return size; 86 | } 87 | 88 | public List keys() { 89 | List keylist = new ArrayList(); 90 | for (int i = 0; i < keys.length; i += 1) { 91 | keylist.add(keys[i]); 92 | } 93 | return keylist; 94 | } 95 | 96 | @Test 97 | public void test() { 98 | ArrayMap am = new ArrayMap(); 99 | am.put(2, 5); 100 | int expected = 5; 101 | assertEquals((Integer) expected, am.get(2)); 102 | } 103 | 104 | public static void main(String[] args) { 105 | ArrayMap m = new ArrayMap(); 106 | m.put("horse", 3); 107 | m.put("fish", 9); 108 | m.put("house", 10); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /exercises/DIY/syntax3/accessControl/syntax3/map/ExceptionDemo.java: -------------------------------------------------------------------------------- 1 | package syntax3.map; 2 | 3 | public class ExceptionDemo { 4 | public static void main(String[] args) { 5 | ArrayMap am = new ArrayMap(); 6 | am.put("hello", 5); 7 | System.out.println(am.get("yolp")); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /exercises/DIY/syntax3/accessControl/syntax3/map/IterationDemo.java: -------------------------------------------------------------------------------- 1 | package syntax3.map; 2 | 3 | import java.util.Iterator; 4 | 5 | public class IterationDemo { 6 | public static void main(String[] args) { 7 | ArrayMap am = new ArrayMap(); 8 | 9 | am.put("hello", 5); 10 | am.put("syrups", 10); 11 | am.put("kingdom", 10); 12 | 13 | Iterator it = am.iterator(); 14 | 15 | for (String s : am) { 16 | System.out.println(s); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /exercises/DIY/syntax3/accessControl/syntax3/map/Map61B.java: -------------------------------------------------------------------------------- 1 | package syntax3.map; 2 | import java.util.List; 3 | 4 | public interface Map61B { 5 | /* Returns true if this map contains a mapping for the specified key. */ 6 | boolean containsKey(K key); 7 | 8 | /* Returns the value to which the specified key is mapped. No defined 9 | * behavior if the key doesn't exist (ok to crash). */ 10 | V get(K key); 11 | 12 | /* Returns the number of key-value mappings in this map. */ 13 | int size(); 14 | 15 | /* Associates the specified value with the specified key in this map. */ 16 | void put(K key, V value); 17 | 18 | /* Returns a list of the keys in this map. */ 19 | List keys(); 20 | } -------------------------------------------------------------------------------- /exercises/DIY/syntax3/accessControl/syntax3/map/MapHelper.java: -------------------------------------------------------------------------------- 1 | package syntax3.map; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | import java.util.List; 8 | 9 | /** 10 | * Class to demonstrate how generic methods work in Java. 11 | */ 12 | public class MapHelper { 13 | /* Write the following three methods: 14 | /* get(Key) : Return item in map if it exists. */ 15 | 16 | public static V get(Map61B sim, K key) { 17 | if (sim.containsKey(key)) { 18 | return sim.get(key); 19 | } 20 | return null; 21 | } 22 | /* maxKey() : Returns max of all keys. Works only if x and y have comparable data. */ 23 | public static , V> K maxKey(Map61B map) { 24 | List keylist = map.keys(); 25 | K largest = keylist.get(0); 26 | for (K k : keylist) { 27 | if (k.compareTo(largest) > 0) { 28 | largest = k; 29 | } 30 | } 31 | return largest; 32 | } 33 | 34 | @Test 35 | public void testGet() { 36 | Map61B m = new ArrayMap(); 37 | m.put("horse", 3); 38 | m.put("fish", 9); 39 | m.put("house", 10); 40 | Integer actual = MapHelper.get(m, "fish"); 41 | Integer expected = 9; 42 | assertEquals(expected, actual); 43 | 44 | Assert.assertEquals(null, MapHelper.get(m, "awefawefawef")); 45 | } 46 | 47 | @Test 48 | public void testMaxKey() { 49 | Map61B m = new ArrayMap(); 50 | m.put("horse", 3); 51 | m.put("fish", 9); 52 | m.put("house", 10); 53 | 54 | String actual = MapHelper.maxKey(m); 55 | String expected = "house"; 56 | assertEquals(expected, actual); 57 | } 58 | 59 | public static void printSize(ArrayMap am) { 60 | System.out.println(am.size()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /exercises/DIY/syntax3/accessControl/syntax3/map/MyonicArrayMap.java: -------------------------------------------------------------------------------- 1 | package syntax3.map; 2 | 3 | /** 4 | * Created by hug. 5 | */ 6 | public class MyonicArrayMap extends ArrayMap { 7 | public MyonicArrayMap(int s) { 8 | size = s; 9 | } 10 | 11 | public static void main(String[] args) { 12 | MyonicArrayMap mam = new MyonicArrayMap<>(5); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /exercises/DIY/syntax3/objectMethods/objectMethods/Date.java: -------------------------------------------------------------------------------- 1 | package objectMethods; 2 | 3 | public class Date { 4 | private final int month; 5 | private final int day; 6 | private final int year; 7 | 8 | public Date(int m, int d, int y) { 9 | month = m; 10 | day = d; 11 | year = y; 12 | } 13 | 14 | @Override 15 | public boolean equals(Object o) { 16 | if (o == null) { 17 | return false; 18 | } 19 | if (this.getClass() != o.getClass()) { 20 | return false; 21 | } 22 | Date uddaDate = (Date) o; 23 | 24 | if (month != uddaDate.month) { 25 | return false; 26 | } 27 | if (day != uddaDate.day) { 28 | return false; 29 | } 30 | if (year != uddaDate.year) { 31 | return false; 32 | } 33 | return true; 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /exercises/DIY/syntax3/objectMethods/objectMethods/DateEqualsTest.java: -------------------------------------------------------------------------------- 1 | package objectMethods; 2 | import org.junit.Test; 3 | import static org.junit.Assert.*; 4 | 5 | public class DateEqualsTest { 6 | @Test 7 | public void testEquals() { 8 | Date d1a = new Date(5, 10, 2010); 9 | Date d1b = new Date(5, 10, 2010); 10 | Date d2 = new Date(10, 11, 2012); 11 | assertEquals(d1a, d1a); 12 | assertEquals(d1a, d1b); 13 | assertNotEquals(d1a, d2); 14 | assertNotEquals(d1a, "horse"); 15 | assertNotEquals(d1a, null); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /exercises/lists1/IntList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Berkeley-CS61B/lectureCode-fa20/2b64638b8187efa5dd3f102aeb15b50f80e76444/exercises/lists1/IntList.class -------------------------------------------------------------------------------- /exercises/lists1/IntList.java: -------------------------------------------------------------------------------- 1 | public class IntList { 2 | public int first; 3 | public IntList rest; 4 | 5 | public IntList(int f, IntList r) { 6 | first = f; 7 | rest = r; 8 | } 9 | 10 | /** Return the size of the list using... recursion! */ 11 | public int size() { 12 | return 0; 13 | } 14 | 15 | /** Return the size of the list using no recursion! */ 16 | public int iterativeSize() { 17 | return 0; 18 | } 19 | 20 | /** Returns the ith value in this list.*/ 21 | public int get(int i) { 22 | return 0; 23 | } 24 | 25 | public static void main(String[] args) { 26 | IntList L = new IntList(15, null); 27 | L = new IntList(10, L); 28 | L = new IntList(5, L); 29 | 30 | System.out.println(L.iterativeSize()); 31 | } 32 | } -------------------------------------------------------------------------------- /exercises/lists1/Lists1Exercises.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Berkeley-CS61B/lectureCode-fa20/2b64638b8187efa5dd3f102aeb15b50f80e76444/exercises/lists1/Lists1Exercises.class -------------------------------------------------------------------------------- /exercises/lists1/Lists1Exercises.java: -------------------------------------------------------------------------------- 1 | public class Lists1Exercises { 2 | /** Returns an IntList identical to L, but with 3 | * each element incremented by x. L is not allowed 4 | * to change. */ 5 | public static IntList incrList(IntList L, int x) { 6 | /* Your code here. */ 7 | return L; 8 | } 9 | 10 | /** Returns an IntList identical to L, but with 11 | * each element incremented by x. Not allowed to use 12 | * the 'new' keyword. */ 13 | public static IntList dincrList(IntList L, int x) { 14 | /* Your code here. */ 15 | return L; 16 | } 17 | 18 | public static void main(String[] args) { 19 | IntList L = new IntList(5, null); 20 | L.rest = new IntList(7, null); 21 | L.rest.rest = new IntList(9, null); 22 | 23 | System.out.println(L.size()); 24 | System.out.println(L.iterativeSize()); 25 | 26 | // Test your answers by uncommenting. Or copy and paste the 27 | // code for incrList and dincrList into IntList.java and 28 | // run it in the visualizer. 29 | // System.out.println(L.get(1)); 30 | // System.out.println(incrList(L, 3)); 31 | // System.out.println(dincrList(L, 3)); 32 | } 33 | } -------------------------------------------------------------------------------- /exercises/lists4/AList.java: -------------------------------------------------------------------------------- 1 | /** Array based list. 2 | * @author Josh Hug 3 | */ 4 | 5 | public class AList { 6 | /** Creates an empty list. */ 7 | public AList() { 8 | } 9 | 10 | /** Inserts X into the back of the list. */ 11 | public void addLast(int x) { 12 | } 13 | 14 | /** Returns the item from the back of the list. */ 15 | public int getLast() { 16 | return 0; 17 | } 18 | /** Gets the ith item in the list (0 is the front). */ 19 | public int get(int i) { 20 | return 0; 21 | } 22 | 23 | /** Returns the number of items in the list. */ 24 | public int size() { 25 | return 0; 26 | } 27 | 28 | /** Deletes item from back of the list and 29 | * returns deleted item. */ 30 | public int removeLast() { 31 | return 0; 32 | } 33 | } -------------------------------------------------------------------------------- /exercises/lists4/AListTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | 4 | /** Tests the AList class. 5 | * @author Josh Hug 6 | */ 7 | 8 | public class AListTest { 9 | @Test 10 | public void testEmptySize() { 11 | AList L = new AList(); 12 | assertEquals(0, L.size()); 13 | } 14 | 15 | @Test 16 | public void testAddAndSize() { 17 | AList L = new AList(); 18 | L.addLast(99); 19 | L.addLast(99); 20 | assertEquals(2, L.size()); 21 | } 22 | 23 | 24 | @Test 25 | public void testAddAndGetLast() { 26 | AList L = new AList(); 27 | L.addLast(99); 28 | assertEquals(99, L.getLast()); 29 | L.addLast(36); 30 | assertEquals(36, L.getLast()); 31 | } 32 | 33 | 34 | @Test 35 | public void testGet() { 36 | AList L = new AList(); 37 | L.addLast(99); 38 | assertEquals(99, L.get(0)); 39 | L.addLast(36); 40 | assertEquals(99, L.get(0)); 41 | assertEquals(36, L.get(1)); 42 | } 43 | 44 | 45 | @Test 46 | public void testRemove() { 47 | AList L = new AList(); 48 | L.addLast(99); 49 | assertEquals(99, L.get(0)); 50 | L.addLast(36); 51 | assertEquals(99, L.get(0)); 52 | L.removeLast(); 53 | assertEquals(99, L.getLast()); 54 | L.addLast(100); 55 | assertEquals(100, L.getLast()); 56 | assertEquals(2, L.size()); 57 | } 58 | 59 | /** Tests insertion of a large number of items.*/ 60 | @Test 61 | public void testMegaInsert() { 62 | AList L = new AList(); 63 | int N = 1000000; 64 | for (int i = 0; i < N; i += 1) { 65 | L.addLast(i); 66 | } 67 | 68 | for (int i = 0; i < N; i += 1) { 69 | L.addLast(L.get(i)); 70 | } 71 | } 72 | 73 | public static void main(String[] args) { 74 | jh61b.junit.TestRunner.runTests("all", AListTest.class); 75 | } 76 | } -------------------------------------------------------------------------------- /inheritance1/AList.java: -------------------------------------------------------------------------------- 1 | /** Array based list. 2 | * @author Josh Hug 3 | */ 4 | 5 | // 0 1 2 3 4 5 6 7 6 | // items: [6 9 -1 2 0 0 0 0 ...] 7 | // size: 5 8 | 9 | /* Invariants: 10 | addLast: The next item we want to add, will go into position size 11 | getLast: The item we want to return is in position size - 1 12 | size: The number of items in the list should be size. 13 | */ 14 | 15 | public class AList implements List61B { 16 | private Item[] items; 17 | private int size; 18 | 19 | /** Creates an empty list. */ 20 | public AList() { 21 | items = (Item[]) new Object[100]; 22 | size = 0; 23 | } 24 | 25 | /** Inserts item into given position. 26 | * Code from discussion #3 */ 27 | @Override 28 | public void insert(Item x, int position) { 29 | Item[] newItems = (Item[]) new Object[items.length + 1]; 30 | 31 | System.arraycopy(items, 0, newItems, 0, position); 32 | newItems[position] = x; 33 | 34 | System.arraycopy(items, position, newItems, position + 1, items.length - position); 35 | items = newItems; 36 | } 37 | 38 | /** Resizes the underlying array to the target capacity. */ 39 | private void resize(int capacity) { 40 | Item[] a = (Item[]) new Object[capacity]; 41 | System.arraycopy(items, 0, a, 0, size); 42 | items = a; 43 | } 44 | 45 | /** Inserts an item at the front. */ 46 | @Override 47 | public void addFirst(Item x) { 48 | insert(x, 0); 49 | } 50 | 51 | /** Inserts X into the back of the list. */ 52 | @Override 53 | public void addLast(Item x) { 54 | if (size == items.length) { 55 | resize(size + 1); 56 | } 57 | 58 | items[size] = x; 59 | size = size + 1; 60 | } 61 | 62 | /** Gets an item from the front. */ 63 | @Override 64 | public Item getFirst() { 65 | return get(0); 66 | } 67 | 68 | /** Returns the item from the back of the list. */ 69 | public Item getLast() { 70 | return items[size - 1]; 71 | } 72 | /** Gets the ith item in the list (0 is the front). */ 73 | public Item get(int i) { 74 | return items[i]; 75 | } 76 | 77 | /** Returns the number of items in the list. */ 78 | public int size() { 79 | return size; 80 | } 81 | 82 | /** Deletes item from back of the list and 83 | * returns deleted item. */ 84 | public Item removeLast() { 85 | Item x = getLast(); 86 | items[size - 1] = null; 87 | size = size - 1; 88 | return x; 89 | } 90 | } -------------------------------------------------------------------------------- /inheritance1/IsADemo.java: -------------------------------------------------------------------------------- 1 | public class IsADemo { 2 | public static void main(String[] args) { 3 | List61B someList = new SLList<>(); 4 | someList.addFirst("elk"); 5 | someList.addLast("dwell"); 6 | someList.addLast("on"); 7 | someList.addLast("existential"); 8 | someList.addLast("crises"); 9 | someList.print(); 10 | } 11 | } -------------------------------------------------------------------------------- /inheritance1/List61B.java: -------------------------------------------------------------------------------- 1 | public interface List61B { 2 | public void insert(Item x, int position); 3 | public void addFirst(Item x); 4 | public void addLast(Item x); 5 | public Item getFirst(); 6 | public Item getLast(); 7 | public Item get(int i); 8 | public int size(); 9 | public Item removeLast(); 10 | default public void print() { 11 | for (int i = 0; i < size(); i += 1) { 12 | System.out.print(get(i) + " "); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /inheritance1/SLList.java: -------------------------------------------------------------------------------- 1 | /** An SLList is a list of integers, which hides the terrible truth 2 | * of the nakedness within. */ 3 | public class SLList implements List61B { 4 | private class Node { 5 | public Blorp item; 6 | public Node next; 7 | 8 | public Node(Blorp i, Node n) { 9 | item = i; 10 | next = n; 11 | } 12 | } 13 | 14 | /* The first item (if it exists) is at sentinel.next. */ 15 | private Node sentinel; 16 | private int size; 17 | 18 | /** Creates an empty SLList. */ 19 | public SLList() { 20 | sentinel = new Node(null, null); 21 | size = 0; 22 | } 23 | 24 | public SLList(Blorp x) { 25 | sentinel = new Node(null, null); 26 | sentinel.next = new Node(x, null); 27 | size = 1; 28 | } 29 | 30 | /** Inserts the item into the given position in 31 | * the list. If position is greater than the 32 | * size of the list, inserts at the end instead. 33 | */ 34 | public void insert(Blorp item, int position) { 35 | Node p = sentinel; 36 | while (position > 1 && p.next != null) { 37 | position--; 38 | p = p.next; 39 | } 40 | Node newNode = new Node(item, p.next); 41 | p.next = newNode; 42 | } 43 | 44 | /** Adds x to the front of the list. */ 45 | public void addFirst(Blorp x) { 46 | sentinel.next = new Node(x, sentinel.next); 47 | size = size + 1; 48 | } 49 | 50 | /** Adds x to the end of the list. */ 51 | public void addLast(Blorp x) { 52 | size = size + 1; 53 | 54 | Node p = sentinel; 55 | 56 | /* Advance p to the end of the list. */ 57 | while (p.next != null) { 58 | p = p.next; 59 | } 60 | 61 | p.next = new Node(x, null); 62 | } 63 | 64 | /** Returns the first item in the list. */ 65 | public Blorp getFirst() { 66 | return sentinel.next.item; 67 | } 68 | 69 | /** Returns the back node of our list. */ 70 | private Node getLastNode() { 71 | Node p = sentinel; 72 | 73 | /* Move p until it reaches the end. */ 74 | while (p.next != null) { 75 | p = p.next; 76 | } 77 | return p; 78 | } 79 | 80 | /** Returns last item */ 81 | public Blorp getLast() { 82 | Node back = getLastNode(); 83 | return back.item; 84 | } 85 | 86 | /** Returns the ith item in the list. */ 87 | public Blorp get(int i) { 88 | return get(i, sentinel.next); 89 | } 90 | 91 | private Blorp get(int i, Node p) { 92 | if (i == 0) { 93 | return p.item; 94 | } 95 | return get(i - 1, p.next); 96 | } 97 | 98 | /** Returns the size of the list. */ 99 | public int size() { 100 | return size; 101 | } 102 | 103 | /** Deletes and returns last item. */ 104 | public Blorp removeLast() { 105 | Node back = getLastNode(); 106 | if (back == sentinel) { 107 | return null; 108 | } 109 | 110 | Node p = sentinel; 111 | 112 | while (p.next != back) { 113 | p = p.next; 114 | } 115 | p.next = null; 116 | return back.item; 117 | } 118 | 119 | @Override 120 | public void print() { 121 | System.out.println("THIS IS THE OVERRIDDEN VERSION."); 122 | Node p = sentinel.next; 123 | while (p != null) { 124 | System.out.print(p.item + " "); 125 | p = p.next; 126 | } 127 | } 128 | 129 | public static void main(String[] args) { 130 | /* Creates a list of one integer, namely 10 */ 131 | SLList L = new SLList(); 132 | L.addLast(20); 133 | System.out.println(L.size()); 134 | } 135 | } -------------------------------------------------------------------------------- /inheritance1/WordUtils.java: -------------------------------------------------------------------------------- 1 | public class WordUtils { 2 | /** Returns the length of the longest word. */ 3 | public static String longest(List61B list) { 4 | int maxDex = 0; 5 | for (int i = 0; i < list.size(); i += 1) { 6 | String longestString = list.get(maxDex); 7 | String thisString = list.get(i); 8 | if (thisString.length() > longestString.length()) { 9 | maxDex = i; 10 | } 11 | } 12 | return list.get(maxDex); 13 | } 14 | 15 | public static void main(String[] args) { 16 | List61B someList = new SLList<>(); 17 | someList.addLast("elk"); 18 | someList.addLast("are"); 19 | someList.addLast("watching"); 20 | System.out.println(longest(someList)); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /inheritance2/HoFDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by hug on 2/6/2017. 3 | * Demonstrates higher order functions in Java. 4 | */ 5 | public class HoFDemo { 6 | public static int do_twice(IntUnaryFunction f, int x) { 7 | return f.apply(f.apply(x)); 8 | } 9 | 10 | public static void main(String[] args) { 11 | IntUnaryFunction tenX = new TenX(); 12 | System.out.println(do_twice(tenX, 2)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /inheritance2/IntUnaryFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by hug on 2/6/2017. 3 | * Represent a function that takes in an integer, and returns an integer. 4 | */ 5 | public interface IntUnaryFunction { 6 | int apply(int x); 7 | } 8 | -------------------------------------------------------------------------------- /inheritance2/List61B.java: -------------------------------------------------------------------------------- 1 | public interface List61B { 2 | /** 3 | * Inserts X into the back of the list. 4 | */ 5 | public void addLast(Item x); 6 | 7 | /** 8 | * Returns the item from the back of the list. 9 | */ 10 | public Item getLast(); 11 | 12 | /** 13 | * Gets the ith item in the list (0 is the front). 14 | */ 15 | public Item get(int i); 16 | 17 | /** 18 | * Returns the number of items in the list. 19 | */ 20 | public int size(); 21 | 22 | /** 23 | * Deletes item from back of the list and 24 | * returns deleted item. 25 | */ 26 | public Item removeLast(); 27 | 28 | /** 29 | * Inserts item into given position. 30 | * Code from discussion #3 31 | */ 32 | public void insert(Item x, int position); 33 | 34 | /** 35 | * Inserts an item at the front. 36 | */ 37 | public void addFirst(Item x); 38 | 39 | /** 40 | * Gets an item from the front. 41 | */ 42 | public Item getFirst(); 43 | 44 | /** Prints the list. Works for ANY kind of list. */ 45 | default public void print() { 46 | for (int i = 0; i < size(); i = i + 1) { 47 | System.out.print(get(i) + " "); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /inheritance2/RotatingSLList.java: -------------------------------------------------------------------------------- 1 | /* SLList, but with additional rotateRight operation. */ 2 | public class RotatingSLList extends SLList { 3 | 4 | /** To do: Implement RotatingSLList such that code compiles and outputs correct result. */ 5 | 6 | /** Rotates list to the right. */ 7 | public void rotateRight() { 8 | Item x = removeLast(); 9 | addFirst(x); 10 | } 11 | 12 | public static void main(String[] args) { 13 | RotatingSLList rsl = new RotatingSLList<>(); 14 | /* Creates SList: [10, 11, 12, 13] */ 15 | rsl.addLast(10); 16 | rsl.addLast(11); 17 | rsl.addLast(12); 18 | rsl.addLast(13); 19 | 20 | /* Should be: [13, 10, 11, 12] */ 21 | rsl.rotateRight(); 22 | rsl.print(); 23 | } 24 | } -------------------------------------------------------------------------------- /inheritance2/SLList.java: -------------------------------------------------------------------------------- 1 | /* Represent a list of stuff, where all the "list" work is delegated 2 | * to a naked recursive data structure. */ 3 | 4 | public class SLList implements List61B { 5 | public class Node { 6 | public Blorp item; /* Equivalent of first */ 7 | public Node next; /* Equivalent of rest */ 8 | 9 | public Node(Blorp i, Node h) { 10 | item = i; 11 | next = h; 12 | } 13 | } 14 | 15 | private Node sentinel; 16 | private int size; 17 | 18 | /** Creates an empty list. */ 19 | public SLList() { 20 | size = 0; 21 | sentinel = new Node(null, null); 22 | } 23 | 24 | public SLList(Blorp x) { 25 | size = 1; 26 | sentinel = new Node(null, null); 27 | sentinel.next = new Node(x, null); 28 | } 29 | 30 | /** Adds an item of the front. */ 31 | public void addFirst(Blorp x) { 32 | Node oldFrontNode = sentinel.next; 33 | Node newNode = new Node(x, oldFrontNode); 34 | sentinel.next = newNode; 35 | size += 1; 36 | } 37 | 38 | /** Gets the front item of the list. */ 39 | public Blorp getFirst() { 40 | return sentinel.next.item; 41 | } 42 | 43 | /** Puts an item at the back of the list. */ 44 | public void addLast(Blorp x) { 45 | size += 1; 46 | 47 | Node p = sentinel; 48 | 49 | /* Move p until it reaches the end. */ 50 | while (p.next != null) { 51 | p = p.next; 52 | } 53 | 54 | p.next = new Node(x, null); 55 | } 56 | 57 | /** Returns the back node of our list. */ 58 | private Node getLastNode() { 59 | Node p = sentinel; 60 | 61 | /* Move p until it reaches the end. */ 62 | while (p.next != null) { 63 | p = p.next; 64 | } 65 | return p; 66 | } 67 | 68 | /** Returns last item */ 69 | public Blorp getLast() { 70 | Node back = getLastNode(); 71 | return back.item; 72 | } 73 | 74 | /** Deletes and returns last item. */ 75 | public Blorp removeLast() { 76 | Node back = getLastNode(); 77 | if (back == sentinel) { 78 | return null; 79 | } 80 | 81 | size = size - 1; 82 | Node p = sentinel; 83 | 84 | while (p.next != back) { 85 | p = p.next; 86 | } 87 | p.next = null; 88 | return back.item; 89 | } 90 | 91 | public int size() { 92 | return size; 93 | } 94 | 95 | /** Gets the positionth item of the list. */ 96 | public Blorp get(int position) { 97 | if (position == 0) { 98 | return getFirst(); 99 | } 100 | Node currentNode = sentinel.next.next; 101 | while (position > 1 && currentNode.next != null) { 102 | position -= 1; 103 | currentNode = currentNode.next; 104 | } 105 | 106 | return currentNode.item; 107 | } 108 | 109 | /** Inserts item into given position. 110 | * Code from discussion #3 */ 111 | public void insert(Blorp item, int position) { 112 | if (sentinel.next == null || position == 0) { 113 | addFirst(item); 114 | return; 115 | } 116 | 117 | Node currentNode = sentinel.next.next; 118 | while (position > 1 && currentNode.next != null) { 119 | position -= 1; 120 | currentNode = currentNode.next; 121 | } 122 | 123 | Node newNode = new Node(item, currentNode.next); 124 | currentNode.next = newNode; 125 | } 126 | 127 | /** TODO: Add a print method that overrides List61B's inefficient print method. */ 128 | 129 | } -------------------------------------------------------------------------------- /inheritance2/TenX.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by hug on 2/6/2017. 3 | */ 4 | public class TenX implements IntUnaryFunction { 5 | /** Returns ten times the argument. */ 6 | public int apply(int x) { 7 | return 10 * x; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /inheritance2/VengefulSLList.java: -------------------------------------------------------------------------------- 1 | /** SList with additional operation printLostItems() which prints all items 2 | * that have ever been deleted. */ 3 | public class VengefulSLList extends SLList { 4 | SLList deletedItems; 5 | 6 | public VengefulSLList() { 7 | super(); 8 | deletedItems = new SLList(); 9 | } 10 | 11 | public VengefulSLList(Item x) { 12 | deletedItems = new SLList(); 13 | } 14 | 15 | @Override 16 | public Item removeLast() { 17 | Item x = super.removeLast(); 18 | deletedItems.addLast(x); 19 | return x; 20 | } 21 | 22 | /** Prints deleted items. */ 23 | public void printLostItems() { 24 | deletedItems.print(); 25 | } 26 | 27 | public static void main(String[] args) { 28 | 29 | VengefulSLList vs1 = new VengefulSLList(0); 30 | vs1.addLast(1); 31 | vs1.addLast(5); 32 | vs1.addLast(10); 33 | vs1.addLast(13); 34 | // vs1 is now: [1, 5, 10, 13] 35 | 36 | 37 | vs1.removeLast(); 38 | vs1.removeLast(); 39 | // After deletion, vs1 is: [1, 5] 40 | 41 | // Should print out the numbers of the fallen, namely 10 and 13. 42 | System.out.print("The fallen are: "); 43 | vs1.printLostItems(); 44 | } 45 | } -------------------------------------------------------------------------------- /inheritance3/Comparator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by jug on 2/7/18. 3 | */ 4 | public interface Comparator { 5 | public int compare(T x1, T x2); 6 | } 7 | -------------------------------------------------------------------------------- /inheritance3/Dog.java: -------------------------------------------------------------------------------- 1 | public class Dog implements Comparable { 2 | public String name; 3 | private int size; 4 | 5 | public Dog(String n, int s) { 6 | name = n; 7 | size = s; 8 | } 9 | 10 | @Override 11 | public int compareTo(Dog uddaDog) { 12 | //assume nobody is messing up and giving us 13 | //something that isn't a dog. 14 | return size - uddaDog.size; 15 | } 16 | 17 | 18 | 19 | public void bark() { 20 | System.out.println(name + " says: bark"); 21 | } 22 | } -------------------------------------------------------------------------------- /inheritance3/DogLauncher.java: -------------------------------------------------------------------------------- 1 | public class DogLauncher { 2 | public static void main(String[] args) { 3 | Dog d1 = new Dog("Elyse", 3); 4 | Dog d2 = new Dog("Sture", 9); 5 | Dog d3 = new Dog("Benjamin", 15); 6 | Dog[] dogs = new Dog[]{d1, d2, d3}; 7 | 8 | Dog d = (Dog) Maximizer.max(dogs); 9 | System.out.println(d.name); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /inheritance3/Maximizer.java: -------------------------------------------------------------------------------- 1 | public class Maximizer { 2 | public static Comparable max(Comparable[] items) { 3 | int maxDex = 0; 4 | for (int i = 0; i < items.length; i += 1) { 5 | int cmp = items[i].compareTo(items[maxDex]); 6 | 7 | if (cmp > 0) { 8 | maxDex = i; 9 | } 10 | } 11 | return items[maxDex]; 12 | } 13 | } -------------------------------------------------------------------------------- /inheritance4/ArraySet.java: -------------------------------------------------------------------------------- 1 | import java.util.Iterator; 2 | 3 | public class ArraySet implements Iterable { 4 | private T[] items; 5 | private int size; // the next item to be added will be at position size 6 | 7 | public ArraySet() { 8 | items = (T[]) new Object[100]; 9 | size = 0; 10 | } 11 | 12 | /* Returns true if this map contains a mapping for the specified key. 13 | */ 14 | public boolean contains(T x) { 15 | for (int i = 0; i < size; i += 1) { 16 | if (items[i].equals(x)) { 17 | return true; 18 | } 19 | } 20 | return false; 21 | } 22 | 23 | /* Associates the specified value with the specified key in this map. 24 | Throws an IllegalArgumentException if the key is null. */ 25 | public void add(T x) { 26 | if (x == null) { 27 | throw new IllegalArgumentException("can't add null"); 28 | } 29 | if (contains(x)) { 30 | return; 31 | } 32 | items[size] = x; 33 | size += 1; 34 | } 35 | 36 | /* Returns the number of key-value mappings in this map. */ 37 | public int size() { 38 | return size; 39 | } 40 | 41 | /** returns an iterator (a.k.a. seer) into ME */ 42 | public Iterator iterator() { 43 | return new ArraySetIterator(); 44 | } 45 | 46 | private class ArraySetIterator implements Iterator { 47 | private int wizPos; 48 | 49 | public ArraySetIterator() { 50 | wizPos = 0; 51 | } 52 | 53 | public boolean hasNext() { 54 | return wizPos < size; 55 | } 56 | 57 | public T next() { 58 | T returnItem = items[wizPos]; 59 | wizPos += 1; 60 | return returnItem; 61 | } 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | StringBuilder returnSB = new StringBuilder("{"); 67 | for (int i = 0; i < size - 1; i += 1) { 68 | returnSB.append(items[i].toString()); 69 | returnSB.append(", "); 70 | } 71 | returnSB.append(items[size - 1]); 72 | returnSB.append("}"); 73 | return returnSB.toString(); 74 | } 75 | 76 | /* EXTRA VIDEO CODE 77 | @Override 78 | public String toString() { 79 | List listOfItems = new ArrayList<>(); 80 | for (T x : this) { 81 | listOfItems.add(x.toString()); 82 | } 83 | return "{" + String.join(", ", listOfItems) + "}"; 84 | } */ 85 | 86 | /* EXTRA VIDEO CODE 87 | public static ArraySet of(Glerp... stuff) { 88 | ArraySet returnSet = new ArraySet(); 89 | for (Glerp x : stuff) { 90 | returnSet.add(x); 91 | } 92 | return returnSet; 93 | } */ 94 | 95 | 96 | @Override 97 | public boolean equals(Object other) { 98 | if (this == other) { 99 | return true; 100 | } 101 | if (other == null) { 102 | return false; 103 | } 104 | if (other.getClass() != this.getClass()) { 105 | return false; 106 | } 107 | ArraySet o = (ArraySet) other; 108 | if (o.size() != this.size()) { 109 | return false; 110 | } 111 | for (T item : this) { 112 | if (!o.contains(item)) { 113 | return false; 114 | } 115 | } 116 | return true; 117 | } 118 | 119 | public static void main(String[] args) { 120 | ArraySet aset = new ArraySet<>(); 121 | aset.add(5); 122 | aset.add(23); 123 | aset.add(42); 124 | 125 | //iteration 126 | for (int i : aset) { 127 | System.out.println(i); 128 | } 129 | 130 | //toString 131 | System.out.println(aset); 132 | 133 | //equals 134 | ArraySet aset2 = new ArraySet<>(); 135 | aset2.add(5); 136 | aset2.add(23); 137 | aset2.add(42); 138 | 139 | System.out.println(aset.equals(aset2)); 140 | System.out.println(aset.equals(null)); 141 | System.out.println(aset.equals("fish")); 142 | System.out.println(aset.equals(aset)); 143 | 144 | //EXTRA VIDEO CODE 145 | //ArraySet asetOfStrings = ArraySet.of("hi", "I'm", "here"); 146 | //System.out.println(asetOfStrings); 147 | } 148 | 149 | /* Also to do: 150 | 1. Make ArraySet implement the Iterable interface. 151 | 2. Implement a toString method. 152 | 3. Implement an equals() method. 153 | */ 154 | } -------------------------------------------------------------------------------- /intro1/HelloNumbers.java: -------------------------------------------------------------------------------- 1 | public class HelloNumbers { 2 | public static void main(String[] args) { 3 | int x = 0; 4 | while (x < 10) { 5 | System.out.println(x); 6 | x = x + 1; 7 | } 8 | 9 | x = "horse"; 10 | } 11 | } 12 | 13 | /* 14 | 1. Before Java variables can be used, they must be declared. 15 | 2. Java variables must have a specific type. 16 | 3. Java variable types can never change. 17 | 4. Types are verified before the code even runs!!! 18 | */ -------------------------------------------------------------------------------- /intro1/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | public static void main(String[] args) { 3 | System.out.println("hello world"); 4 | } 5 | } 6 | 7 | /* 8 | 1. All code in Java must be part of a class. 9 | 2. We delimit the beginning and end of segments of code 10 | using { and }. 11 | 3. All statements in Java must end in a semi-colon. 12 | 4. For code to run we need public static void main(String[] args) 13 | */ -------------------------------------------------------------------------------- /intro1/LargerDemo.java: -------------------------------------------------------------------------------- 1 | public class LargerDemo { 2 | /** Returns the larger of x and y. */ 3 | public static int larger(int x, int y) { 4 | if (x > y) { 5 | return x; 6 | } 7 | return y; 8 | } 9 | 10 | public static void main(String[] args) { 11 | System.out.println(larger(-5.5, 10)); 12 | } 13 | } 14 | 15 | /* 16 | 1. Functions must be declared as part of a class in Java. 17 | A function that is part of a class is called a "method". 18 | So in Java, all functions are methods. 19 | 2. To define a function in Java, we use "public static". 20 | We will see alternate ways of defining functions later. 21 | 3. All parameters of a function must have a declared type, 22 | and the return value of the function must have a declared type. 23 | Functions in Java return only one value! 24 | */ -------------------------------------------------------------------------------- /intro1/hello.py: -------------------------------------------------------------------------------- 1 | print("hello world") -------------------------------------------------------------------------------- /intro1/hellonumbers.py: -------------------------------------------------------------------------------- 1 | x = 0 2 | while x < 10: 3 | print(x) 4 | x = x + 1 5 | 6 | x = "horse" 7 | print(x) 8 | 9 | print(5 + "horse") -------------------------------------------------------------------------------- /intro1/larger.py: -------------------------------------------------------------------------------- 1 | def larger(x, y): 2 | """Returns the larger of x and y.""" 3 | if (x > y): 4 | return x 5 | return y 6 | 7 | print(larger(-5, 10)) -------------------------------------------------------------------------------- /intro2/ArgsDemo.java: -------------------------------------------------------------------------------- 1 | public class ArgsDemo { 2 | public static void main(String[] args) { 3 | System.out.println(args[0]); 4 | } 5 | } -------------------------------------------------------------------------------- /intro2/ArgsSum.java: -------------------------------------------------------------------------------- 1 | public class ArgsSum { 2 | public static void main(String[] args) { 3 | int N = args.length; 4 | int i = 0; 5 | int sum = 0; 6 | while (i < N) { 7 | sum = sum + Integer.parseInt(args[i]); 8 | i = i + 1; 9 | } 10 | System.out.println(sum); 11 | } 12 | } -------------------------------------------------------------------------------- /intro2/Dog.java: -------------------------------------------------------------------------------- 1 | public class Dog { 2 | public int weightInPounds; 3 | public static String binomen = "Canis familiaris"; 4 | 5 | /** One integer constructor for dogs. */ 6 | public Dog(int w) { 7 | weightInPounds = w; 8 | } 9 | 10 | public void makeNoise() { 11 | if (weightInPounds < 10) { 12 | System.out.println("yip!"); 13 | } else if (weightInPounds < 30) { 14 | System.out.println("bark."); 15 | } else { 16 | System.out.println("woooof!"); 17 | } 18 | } 19 | 20 | public static Dog maxDog(Dog d1, Dog d2) { 21 | if (d1.weightInPounds > d2.weightInPounds) { 22 | return d1; 23 | } 24 | return d2; 25 | } 26 | 27 | 28 | } -------------------------------------------------------------------------------- /intro2/DogLauncher.java: -------------------------------------------------------------------------------- 1 | public class DogLauncher { 2 | public static void main(String[] args) { 3 | Dog d = new Dog(15); 4 | 5 | Dog d2 = new Dog(100); 6 | 7 | //Dog bigger = Dog.maxDog(d, d2); 8 | Dog bigger = d.maxDog(d2); 9 | bigger.makeNoise(); 10 | 11 | //System.out.println(d.binomen); 12 | //System.out.println(d2.binomen); 13 | //System.out.println(Dog.binomen); 14 | // d.makeNoise(); 15 | } 16 | } -------------------------------------------------------------------------------- /intro2/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | public static void main(String[] args) { 3 | System.out.println("Hello World!"); 4 | } 5 | } -------------------------------------------------------------------------------- /library/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Berkeley-CS61B/lectureCode-fa20/2b64638b8187efa5dd3f102aeb15b50f80e76444/library/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /library/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Berkeley-CS61B/lectureCode-fa20/2b64638b8187efa5dd3f102aeb15b50f80e76444/library/junit-4.12.jar -------------------------------------------------------------------------------- /lists1/IntList.java: -------------------------------------------------------------------------------- 1 | public class IntList { 2 | public int first; 3 | public IntList rest; 4 | 5 | public IntList(int f, IntList r) { 6 | first = f; 7 | rest = r; 8 | } 9 | 10 | /** Return the size of the list using... recursion! */ 11 | public int size() { 12 | if (rest == null) { 13 | return 1; 14 | } 15 | return 1 + this.rest.size(); 16 | } 17 | 18 | /** Return the size of the list using no recursion! */ 19 | public int iterativeSize() { 20 | IntList p = this; 21 | int totalSize = 0; 22 | while (p != null) { 23 | totalSize += 1; 24 | p = p.rest; 25 | } 26 | return totalSize; 27 | } 28 | 29 | /** Returns the ith item of this IntList. */ 30 | public int get(int i) { 31 | if (i == 0) { 32 | return first; 33 | } 34 | return rest.get(i - 1); 35 | } 36 | 37 | public static void main(String[] args) { 38 | IntList L = new IntList(15, null); 39 | L = new IntList(10, L); 40 | L = new IntList(5, L); 41 | 42 | System.out.println(L.get(100)); 43 | } 44 | } -------------------------------------------------------------------------------- /lists2/IntList.java: -------------------------------------------------------------------------------- 1 | public class IntList { 2 | public int first; 3 | public IntList rest; 4 | 5 | public IntList(int f, IntList r) { 6 | first = f; 7 | rest = r; 8 | } 9 | 10 | /** Return the size of the list using... recursion! */ 11 | public int size() { 12 | if (rest == null) { 13 | return 1; 14 | } 15 | return 1 + this.rest.size(); 16 | } 17 | 18 | /** Return the size of the list using no recursion! */ 19 | public int iterativeSize() { 20 | IntList p = this; 21 | int totalSize = 0; 22 | while (p != null) { 23 | totalSize += 1; 24 | p = p.rest; 25 | } 26 | return totalSize; 27 | } 28 | 29 | /** Returns the ith item of this IntList. */ 30 | public int get(int i) { 31 | if (i == 0) { 32 | return first; 33 | } 34 | return rest.get(i - 1); 35 | } 36 | 37 | public static void main(String[] args) { 38 | IntList L = new IntList(15, null); 39 | L = new IntList(10, L); 40 | L = new IntList(5, L); 41 | 42 | System.out.println(L.get(100)); 43 | } 44 | } -------------------------------------------------------------------------------- /lists2/IntNode.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Berkeley-CS61B/lectureCode-fa20/2b64638b8187efa5dd3f102aeb15b50f80e76444/lists2/IntNode.java -------------------------------------------------------------------------------- /lists2/SLList.java: -------------------------------------------------------------------------------- 1 | /** An SLList is a list of integers, which hides the terrible truth 2 | * of the nakedness within. */ 3 | public class SLList { 4 | private static class IntNode { 5 | public int item; 6 | public IntNode next; 7 | 8 | public IntNode(int i, IntNode n) { 9 | item = i; 10 | next = n; 11 | System.out.println(size); 12 | } 13 | } 14 | 15 | /* The first item (if it exists) is at sentinel.next. */ 16 | private IntNode sentinel; 17 | private int size; 18 | 19 | private static void lectureQuestion() { 20 | SLList L = new SLList(); 21 | IntNode n = IntNode(5, null); 22 | } 23 | 24 | /** Creates an empty SLList. */ 25 | public SLList() { 26 | sentinel = new IntNode(63, null); 27 | size = 0; 28 | } 29 | 30 | public SLList(int x) { 31 | sentinel = new IntNode(63, null); 32 | sentinel.next = new IntNode(x, null); 33 | size = 1; 34 | } 35 | 36 | /** Adds x to the front of the list. */ 37 | public void addFirst(int x) { 38 | sentinel.next = new IntNode(x, sentinel.next); 39 | size = size + 1; 40 | } 41 | 42 | /** Returns the first item in the list. */ 43 | public int getFirst() { 44 | return sentinel.next.item; 45 | } 46 | 47 | /** Adds x to the end of the list. */ 48 | public void addLast(int x) { 49 | size = size + 1; 50 | 51 | IntNode p = sentinel; 52 | 53 | /* Advance p to the end of the list. */ 54 | while (p.next != null) { 55 | p = p.next; 56 | } 57 | 58 | p.next = new IntNode(x, null); 59 | } 60 | 61 | /** Returns the size of the list. */ 62 | public int size() { 63 | return size; 64 | } 65 | 66 | public static void main(String[] args) { 67 | /* Creates a list of one integer, namely 10 */ 68 | SLList L = new SLList(); 69 | L.addLast(20); 70 | System.out.println(L.size()); 71 | } 72 | } -------------------------------------------------------------------------------- /lists3/ArrayBasics.java: -------------------------------------------------------------------------------- 1 | /** ArrayBasics 2 | * @author Josh Hug 3 | */ 4 | 5 | public class ArrayBasics { 6 | /** ArrayBasics */ 7 | public static void main(String[] args) { 8 | int[] z = null; 9 | int[] x, y; 10 | 11 | x = new int[]{1, 2, 3, 4, 5}; 12 | y = x; 13 | x = new int[]{-1, 2, 5, 4, 99}; 14 | y = new int[3]; 15 | z = new int[0]; 16 | 17 | String[] s = new String[6]; 18 | s[4] = "ketchup"; 19 | s[x[3] - x[1]] = "muffins"; 20 | 21 | int[] b = {9, 10, 11}; 22 | System.arraycopy(b, 0, x, 3, 2); 23 | } 24 | } -------------------------------------------------------------------------------- /lists3/ArrayBasics2.java: -------------------------------------------------------------------------------- 1 | /** ArrayBasics 2 | * @author Josh Hug 3 | */ 4 | 5 | public class ArrayBasics2 { 6 | /** ArrayBasics 7 | */ 8 | 9 | public static void main(String[] args) { 10 | int[][] pascalsTriangle; 11 | pascalsTriangle = new int[4][]; 12 | int[] rowZero = pascalsTriangle[0]; 13 | 14 | pascalsTriangle[0] = new int[]{1}; 15 | pascalsTriangle[1] = new int[]{1, 1}; 16 | pascalsTriangle[2] = new int[]{1, 2, 1}; 17 | pascalsTriangle[3] = new int[]{1, 3, 3, 1}; 18 | int[] rowTwo = pascalsTriangle[2]; 19 | rowTwo[1] = -5; 20 | 21 | int[][] matrix; 22 | matrix = new int[4][]; 23 | matrix = new int[4][4]; 24 | 25 | int[][] pascalAgain = new int[][]{{1}, {1, 1}, 26 | {1, 2, 1}, {1, 3, 3, 1}}; 27 | } 28 | } -------------------------------------------------------------------------------- /lists3/ArrayDanger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Josh Hug 3 | */ 4 | 5 | public class ArrayDanger { 6 | 7 | public static void main(String[] args) { 8 | int[][] x = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 9 | 10 | int[][] z = new int[3][]; 11 | z[0] = x[0]; 12 | z[1] = x[1]; 13 | z[2] = x[2]; 14 | z[0][0] = -z[0][0]; 15 | 16 | int[][] w = new int[3][3]; 17 | System.arraycopy(x[0], 0, w[0], 0, 3); 18 | System.arraycopy(x[1], 0, w[1], 0, 3); 19 | System.arraycopy(x[2], 0, w[2], 0, 3); 20 | w[0][0] = -w[0][0]; 21 | } 22 | 23 | 24 | } -------------------------------------------------------------------------------- /lists3/ArraysBasics2.java: -------------------------------------------------------------------------------- 1 | /** ArrayBasics 2 | * @author Josh Hug 3 | */ 4 | 5 | public class ArrayBasics2 { 6 | /** ArrayBasics 7 | */ 8 | 9 | public static void main(String[] args) { 10 | int[][] pascalsTriangle; 11 | pascalsTriangle = new int[4][]; 12 | int[] rowZero = pascalsTriangle[0]; 13 | 14 | pascalsTriangle[0] = new int[]{1}; 15 | pascalsTriangle[1] = new int[]{1, 1}; 16 | pascalsTriangle[2] = new int[]{1, 2, 1}; 17 | pascalsTriangle[3] = new int[]{1, 3, 3, 1}; 18 | int[] rowTwo = pascalsTriangle[2]; 19 | rowTwo[1] = -5; 20 | 21 | int[][] matrix; 22 | matrix = new int[4][]; 23 | matrix = new int[4][4]; 24 | 25 | int[][] pascalAgain = new int[][]{{1}, {1, 1}, 26 | {1, 2, 1}, {1, 3, 3, 1}}; 27 | } 28 | } -------------------------------------------------------------------------------- /lists3/SLList.java: -------------------------------------------------------------------------------- 1 | /** An SLList is a list of integers, which hides the terrible truth 2 | * of the nakedness within. */ 3 | public class SLList { 4 | private class StuffNode { 5 | public LochNess item; 6 | public StuffNode next; 7 | 8 | public StuffNode(LochNess i, StuffNode n) { 9 | item = i; 10 | next = n; 11 | } 12 | } 13 | 14 | private StuffNode first; 15 | private int size; 16 | 17 | public SLList(LochNess x) { 18 | first = new StuffNode(x, null); 19 | size = 1; 20 | } 21 | 22 | /** Adds x to the front of the list. */ 23 | public void addFirst(LochNess x) { 24 | first = new StuffNode(x, first); 25 | size += 1; 26 | } 27 | 28 | /** Returns the first item in the list. */ 29 | public LochNess getFirst() { 30 | return first.item; 31 | } 32 | 33 | /** Adds an item to the end of the list. */ 34 | public void addLast(LochNess x) { 35 | size += 1; 36 | 37 | StuffNode p = first; 38 | 39 | /* Move p until it reaches the end of the list. */ 40 | while (p.next != null) { 41 | p = p.next; 42 | } 43 | 44 | p.next = new StuffNode(x, null); 45 | } 46 | 47 | public int size() { 48 | return size; 49 | } 50 | } -------------------------------------------------------------------------------- /lists3/SLListLauncher.java: -------------------------------------------------------------------------------- 1 | public class SLListLauncher { 2 | public static void main(String[] args) { 3 | SLList s1 = new SLList<>("bone"); 4 | s1.addFirst("thugs"); 5 | } 6 | } -------------------------------------------------------------------------------- /lists4/AList.java: -------------------------------------------------------------------------------- 1 | /** Array based list. 2 | * @author Josh Hug 3 | */ 4 | 5 | // 0 1 2 3 4 5 6 7 6 | // items: [6 9 -1 2 0 0 0 0 ...] 7 | // size: 5 8 | 9 | /* Invariants: 10 | addLast: The next item we want to add, will go into position size 11 | getLast: The item we want to return is in position size - 1 12 | size: The number of items in the list should be size. 13 | */ 14 | 15 | public class AList { 16 | private Item[] items; 17 | private int size; 18 | 19 | /** Creates an empty list. */ 20 | public AList() { 21 | items = (Item[]) new Object[100]; 22 | size = 0; 23 | } 24 | 25 | /** Resizes the underlying array to the target capacity. */ 26 | private void resize(int capacity) { 27 | Item[] a = (Item[]) new Object[capacity]; 28 | System.arraycopy(items, 0, a, 0, size); 29 | items = a; 30 | } 31 | 32 | /** Inserts X into the back of the list. */ 33 | public void addLast(Item x) { 34 | if (size == items.length) { 35 | resize(size + 1); 36 | } 37 | 38 | items[size] = x; 39 | size = size + 1; 40 | } 41 | 42 | /** Returns the item from the back of the list. */ 43 | public Item getLast() { 44 | return items[size - 1]; 45 | } 46 | /** Gets the ith item in the list (0 is the front). */ 47 | public Item get(int i) { 48 | return items[i]; 49 | } 50 | 51 | /** Returns the number of items in the list. */ 52 | public int size() { 53 | return size; 54 | } 55 | 56 | /** Deletes item from back of the list and 57 | * returns deleted item. */ 58 | public Item removeLast() { 59 | Item x = getLast(); 60 | items[size - 1] = null; 61 | size = size - 1; 62 | return x; 63 | } 64 | } -------------------------------------------------------------------------------- /lists4/AListTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | 4 | /** Tests the AList class. 5 | * @author Josh Hug 6 | */ 7 | 8 | public class AListTest { 9 | @Test 10 | public void testEmptySize() { 11 | AList L = new AList(); 12 | assertEquals(0, L.size()); 13 | } 14 | 15 | @Test 16 | public void testAddAndSize() { 17 | AList L = new AList(); 18 | L.addLast(99); 19 | L.addLast(99); 20 | assertEquals(2, L.size()); 21 | } 22 | 23 | 24 | @Test 25 | public void testAddAndGetLast() { 26 | AList L = new AList(); 27 | L.addLast(99); 28 | assertEquals(99, L.getLast()); 29 | L.addLast(36); 30 | assertEquals(36, L.getLast()); 31 | } 32 | 33 | 34 | @Test 35 | public void testGet() { 36 | AList L = new AList(); 37 | L.addLast(99); 38 | assertEquals(99, L.get(0)); 39 | L.addLast(36); 40 | assertEquals(99, L.get(0)); 41 | assertEquals(36, L.get(1)); 42 | } 43 | 44 | 45 | @Test 46 | public void testRemove() { 47 | AList L = new AList(); 48 | L.addLast(99); 49 | assertEquals(99, L.get(0)); 50 | L.addLast(36); 51 | assertEquals(99, L.get(0)); 52 | L.removeLast(); 53 | assertEquals(99, L.getLast()); 54 | L.addLast(100); 55 | assertEquals(100, L.getLast()); 56 | assertEquals(2, L.size()); 57 | } 58 | 59 | /** Tests insertion of a large number of items.*/ 60 | @Test 61 | public void testMegaInsert() { 62 | AList L = new AList(); 63 | int N = 1000000; 64 | for (int i = 0; i < N; i += 1) { 65 | L.addLast(i); 66 | } 67 | 68 | for (int i = 0; i < N; i += 1) { 69 | L.addLast(L.get(i)); 70 | } 71 | } 72 | 73 | public static void main(String[] args) { 74 | jh61b.junit.TestRunner.runTests("all", AListTest.class); 75 | } 76 | } -------------------------------------------------------------------------------- /lists4/speedtest/AList.java: -------------------------------------------------------------------------------- 1 | /** Array based list. 2 | * @author Josh Hug 3 | */ 4 | 5 | // 0 1 2 3 4 5 6 7 6 | // items: [6 9 -1 2 0 0 0 0 ...] 7 | // size: 5 8 | 9 | /* Invariants: 10 | addLast: The next item we want to add, will go into position size 11 | getLast: The item we want to return is in position size - 1 12 | size: The number of items in the list should be size. 13 | */ 14 | 15 | public class AList { 16 | private int[] items; 17 | private int size; 18 | 19 | /** Creates an empty list. */ 20 | public AList() { 21 | items = new int[100]; 22 | size = 0; 23 | } 24 | 25 | /** Resizes the underlying array to the target capacity. */ 26 | private void resize(int capacity) { 27 | int[] a = new int[capacity]; 28 | System.arraycopy(items, 0, a, 0, size); 29 | items = a; 30 | } 31 | 32 | /** Inserts X into the back of the list. */ 33 | public void addLast(int x) { 34 | if (size == items.length) { 35 | resize(size + 100); 36 | } 37 | 38 | items[size] = x; 39 | size = size + 1; 40 | } 41 | 42 | /** Returns the item from the back of the list. */ 43 | public int getLast() { 44 | return items[size - 1]; 45 | } 46 | /** Gets the ith item in the list (0 is the front). */ 47 | public int get(int i) { 48 | return items[i]; 49 | } 50 | 51 | /** Returns the number of items in the list. */ 52 | public int size() { 53 | return size; 54 | } 55 | 56 | /** Deletes item from back of the list and 57 | * returns deleted item. */ 58 | public int removeLast() { 59 | int x = getLast(); 60 | size = size - 1; 61 | return x; 62 | } 63 | } -------------------------------------------------------------------------------- /lists4/speedtest/SLList.java: -------------------------------------------------------------------------------- 1 | /** An SLList is a list of integers, which hides the terrible truth 2 | * of the nakedness within. */ 3 | public class SLList { 4 | private class StuffNode { 5 | public Blah item; 6 | public StuffNode next; 7 | 8 | public StuffNode(Blah i, StuffNode n) { 9 | item = i; 10 | next = n; 11 | } 12 | } 13 | 14 | /* The first item (if it exists) is at sentinel.next. */ 15 | private StuffNode sentinel; 16 | private int size; 17 | 18 | /** Creates an empty SLList. */ 19 | public SLList() { 20 | sentinel = new StuffNode(null, null); 21 | size = 0; 22 | } 23 | 24 | public SLList(Blah x) { 25 | sentinel = new StuffNode(null, null); 26 | sentinel.next = new StuffNode(x, null); 27 | size = 1; 28 | } 29 | 30 | /** Adds x to the front of the list. */ 31 | public void addFirst(Blah x) { 32 | sentinel.next = new StuffNode(x, sentinel.next); 33 | size = size + 1; 34 | } 35 | 36 | /** Returns the first item in the list. */ 37 | public Blah getFirst() { 38 | return sentinel.next.item; 39 | } 40 | 41 | /** Adds x to the end of the list. */ 42 | public void addLast(Blah x) { 43 | size = size + 1; 44 | 45 | StuffNode p = sentinel; 46 | 47 | /* Advance p to the end of the list. */ 48 | while (p.next != null) { 49 | p = p.next; 50 | } 51 | 52 | p.next = new StuffNode(x, null); 53 | } 54 | 55 | /** Returns the size of the list. */ 56 | public int size() { 57 | return size; 58 | } 59 | 60 | public static void main(String[] args) { 61 | SLList L = new SLList<>(); 62 | 63 | } 64 | } -------------------------------------------------------------------------------- /lists4/speedtest/SpeedTestAList.java: -------------------------------------------------------------------------------- 1 | public class SpeedTestAList { 2 | public static void main(String[] args) { 3 | AList L = new AList(); 4 | int i = 0; 5 | while (i < 10000000) { 6 | L.addLast(i); 7 | i = i + 1; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /lists4/speedtest/SpeedTestSLList.java: -------------------------------------------------------------------------------- 1 | public class SpeedTestSLList { 2 | public static void main(String[] args) { 3 | SLList L = new SLList<>(); 4 | int i = 0; 5 | while (i < 10000000) { 6 | L.addFirst(i); 7 | i = i + 1; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /testing/.idea/libraries/library.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /testing/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /testing/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /testing/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 57 | 58 | 59 | 64 | 67 | 68 | 69 | 76 | 77 | 78 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 106 | 107 | 110 | 111 | 112 | 113 | 116 | 117 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 149 | 150 | 151 | 152 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 198 | 199 | 200 | 226 | 227 | 228 | 253 | 254 | 261 | 262 | 263 | 276 | 277 | 278 | 285 | 288 | 290 | 291 | 292 | 293 | 294 | 295 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 334 | 335 | 336 | 347 | 348 | 349 | 359 | 360 | 367 | 368 | 369 | 370 | 388 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 1515536139888 418 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 494 | 495 | 496 | 498 | 499 | 500 | 501 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 605 | 606 | 607 | 608 | 609 | 610 | No facets are configured 611 | 612 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 628 | 629 | 630 | 631 | 632 | 633 | 1.8 634 | 635 | 640 | 641 | 642 | 643 | 644 | 645 | testing 646 | 647 | 653 | 654 | 655 | 656 | 657 | 658 | 1.8 659 | 660 | 665 | 666 | 667 | 668 | 669 | 670 | library 671 | 672 | 677 | 678 | 679 | 680 | 681 | 682 | -------------------------------------------------------------------------------- /testing/Sort.java: -------------------------------------------------------------------------------- 1 | public class Sort { 2 | /** Sorts strings destructively. */ 3 | public static void sort(String[] x) { 4 | sort(x, 0); 5 | } 6 | 7 | /** Sorts x starting at position start. */ 8 | private static void sort(String[] x, int start) { 9 | if (start == x.length) { 10 | return; 11 | } 12 | int smallestIndex = findSmallest(x, start); 13 | swap(x, start, smallestIndex); 14 | sort(x, start + 1); 15 | } 16 | 17 | /** Swap item a with b. */ 18 | public static void swap(String[] x, int a, int b) { 19 | String temp = x[a]; 20 | x[a] = x[b]; 21 | x[b] = temp; 22 | } 23 | 24 | /** Return the index of the smallest String in x, starting at start. */ 25 | public static int findSmallest(String[] x, int start) { 26 | int smallestIndex = start; 27 | for (int i = start; i < x.length; i += 1) { 28 | int cmp = x[i].compareTo(x[smallestIndex]); 29 | // from the internet, if x[i] < x[smallestIndex], cmp will be -1. 30 | if (cmp < 0) { 31 | smallestIndex = i; 32 | } 33 | } 34 | return smallestIndex; 35 | } 36 | } -------------------------------------------------------------------------------- /testing/TestSort.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | 4 | /** Tests the the Sort class. */ 5 | public class TestSort { 6 | /** Test the Sort.sort method. */ 7 | @Test 8 | public void testSort() { 9 | String[] input = {"i", "have", "an", "egg"}; 10 | String[] expected = {"an", "egg", "have", "i"}; 11 | 12 | Sort.sort(input); 13 | 14 | assertArrayEquals(expected, input); 15 | } 16 | 17 | /** Test the Sort.findSmallest method. */ 18 | @Test 19 | public void testFindSmallest() { 20 | String[] input = {"i", "have", "an", "egg"}; 21 | int expected = 2; 22 | 23 | int actual = Sort.findSmallest(input, 0); 24 | assertEquals(expected, actual); 25 | 26 | String[] input2 = {"there", "are", "many", "pigs"}; 27 | int expected2 = 2; 28 | 29 | int actual2 = Sort.findSmallest(input2, 2); 30 | assertEquals(expected2, actual2); 31 | } 32 | 33 | /** Test the Sort.swap method. */ 34 | @Test 35 | public void testSwap() { 36 | String[] input = {"i", "have", "an", "egg"}; 37 | int a = 0; 38 | int b = 2; 39 | String[] expected = {"an", "have", "i", "egg"}; 40 | 41 | Sort.swap(input, a, b); 42 | assertArrayEquals(expected, input); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /testing/out/production/testing/.idea/libraries/library.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /testing/out/production/testing/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /testing/out/production/testing/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /testing/out/production/testing/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 57 | 60 | 61 | 62 | 68 | 69 | 70 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 98 | 99 | 102 | 103 | 104 | 105 | 108 | 109 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 141 | 142 | 143 | 144 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 190 | 191 | 192 | 218 | 219 | 220 | 245 | 246 | 253 | 254 | 255 | 268 | 269 | 270 | 277 | 280 | 282 | 283 | 284 | 285 | 286 | 287 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 326 | 327 | 328 | 339 | 340 | 341 | 351 | 352 | 359 | 360 | 361 | 362 | 380 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 1515536139888 410 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 486 | 487 | 488 | 490 | 491 | 492 | 493 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 557 | 558 | 559 | 560 | 561 | 562 | No facets are configured 563 | 564 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 580 | 581 | 582 | 583 | 584 | 585 | 1.8 586 | 587 | 592 | 593 | 594 | 595 | 596 | 597 | testing 598 | 599 | 605 | 606 | 607 | 608 | 609 | 610 | 1.8 611 | 612 | 617 | 618 | 619 | 620 | 621 | 622 | library 623 | 624 | 629 | 630 | 631 | 632 | 633 | 634 | -------------------------------------------------------------------------------- /testing/out/production/testing/Sort.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Berkeley-CS61B/lectureCode-fa20/2b64638b8187efa5dd3f102aeb15b50f80e76444/testing/out/production/testing/Sort.class -------------------------------------------------------------------------------- /testing/out/production/testing/TestSort.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Berkeley-CS61B/lectureCode-fa20/2b64638b8187efa5dd3f102aeb15b50f80e76444/testing/out/production/testing/TestSort.class -------------------------------------------------------------------------------- /testing/out/production/testing/testing.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /testing/testing.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | --------------------------------------------------------------------------------