/avatar.jpg

61B-5: DLLists, Arrays

Doubly Linked Lists 注意只有sentinel时要讨论一些特殊情况,特别是环状链表。 Generic Lists 泛型列表 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 public class SLList<BleepBlorp> { private IntNode sentinel; private int size; public class IntNode { public BleepBlorp item; public IntNode next; ... } ... } SLList<Integer> s1 = new SLList<>(5); s1.insertFront(10); SLList<String> s2 = new SLList<>("hi"); s2.insertFront("apple"); Arrays, AList 介绍了System.arraycopy()用来resize 2D Arrays Arrays vs. Classes array的runtime动态索引(和cpp不一样) class runtime

61B-6: ALists, Resizing, vs. SLists

A Last Look at Linked Lists Naive Array Lists 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 public class AList { private int[] items; private int size; public AList() { items = new int[100]; size = 0; } public void addLast(int x) { items[size] = x; size += 1; } public int getLast() { return items[size - 1]; } public int get(int i) { return items[i]; } public int size() { return size; } } Resizing Arrays 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 public void addLast(int x) { if (size == items.

61B-1: Intro, Hello World Java

java oop Java is an object oriented language with strict requirements: Every Java file must contain a class declaration*. All code lives inside a class*, even helper functions, global constants, etc. To run a Java program, you typically define a main method using 1 public static void main(String[] args) *: This is not completely true, e.g. we can also declare “interfaces” in .Java files that may contain code. We’ll cover these later.