Archive: http://inst.eecs.berkeley.edu/~cs61b/archives.html
Spring 2019: https://sp19.datastructur.es
Spring 2018: https://sp18.datastructur.es
LectureCode: https://github.com/Berkeley-CS61B/lectureCode
Autograder: https://www.gradescope.com (To sign up, use the entry code 93PK75)
The autograder is now open to the public. Sign up using entry code MNXYKX at gradescope.com.
grepcode.
A Java Reference: http://www-inst.eecs.berkeley.edu/~cs61b/fa14/book1/java.pdf
Head First Java: https://www.safaribooksonline.com/library/view/head-first-java/0596009208/
其他资源:
https://www.1point3acres.com/bbs/thread-282583-1-1.html
这是数据结构讲义:
https://inst.eecs.berkeley.edu/~cs61b/fa18/materials/book2/data-structures.pdf
这是Java讲义:
https://inst.eecs.berkeley.edu/~cs61b/fa18/materials/book1/java.pdf
IntelliJ IDEA破解版教程:https://blog.csdn.net/qq_42914528/article/details/89710864
IntelliJ IDEA遇到的一些问题
- Class file not found in IntelliJ https://stackoverflow.com/questions/2199711/class-file-not-found-in-intellij
这门课边看边学。
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
- Syntax 4: (optional) Encapsulation, Lists, Delegation vs. Extension https://www.youtube.com/watch?v=AYPOTwW9rR4
作业中做错的地方:
- disc02: Scope; Pass-by-Value; Static:
- Pass-by-What? 注意java的Pass-by-Value按值传递。看disc02的第一题。
- Static Methods! 看disc02的第二题。
- Mac的
rm
指令没法在回收站里找到。。。突然脑抽把mv
达成rm
,结果文件被删没了。。。解决方法参考这个 https://www.jianshu.com/p/5552f3340682
0 - Scope! 看disc02-examprep的第二题Horse-Cult。Since the variable same is declared within if statement, it is not accessible outside the if block. Therefore in the return statement, it would find the same variable cult self. Different from Python https://stackoverflow.com/questions/48654795/why-does-this-pointer-point-to-horse-cult-instead-of-horse-horse
- disc03:
- SLList: insert; reverse(iterative and recursive)
- AList: insert; reverse(iterative and recursive), replicate
- proj1a: Double Ended Queue (DataStructure: Deque)
- proj1b: Palindrome and OffByN (HoFs)
- disc04 exam prep
- distinguish overload from override
- Upcasting (always safe) and downcasting (allowable but can be dangerous).
- 第四题值得再看看一看
- class: Syntax: ArrapMap implementation:
note: “x == y” means asking “are these two pointing to the same object” ? so you probably want to use (x.equals(y)).
Textbook: CS61B
https://joshhug.gitbooks.io/hug61b/content/chap1/chap11.html
-
Week 0 : Welcome to CS61B & Course Policies and Logistics
-
Week 1 (1/17-1/19) : Intro, Hello World Java & Defining and Using Classes.
- All functions are methods. Functions in Java return only one value.
- Java is an object oriented language with strict requirements:
- Every Java file must contain a class declaration*( This is not completely true, we can also declare “interfaces” in .Java files that may contain code. We’ll cover these later).
- All codes lives inside a class*, even helper functions, global constants, etc.
- To run a Java program, you typically define a main method using
public static void main(String[] args)
- Java is statically typed!
- All variables, parameters, and methods must have a declared type.
- That type can never change.
- Expressions also have a type.
- The compiler checks that all the types in your program are compatible before the program ever runs! (This is unlike Python, where type checks are performed DURING execution)
- Style Guide!!! https://sp19.datastructur.es/materials/guides/style-guide.html
- Javadoc comments: https://en.wikipedia.org/wiki/Javadoc
- Defining a Typical Class (Terminology)
- Instance variable.
- Constructor
- Non-static method, a.k.a. Instance Method.
- Roughly speaking: If the method needs to use “my instance variables”, the method must be non-static.
- Instantiating a Class and Terminology
- Declaration of a Dog variable
- Instantiation of the Dog class as a Dog Object.
- Instantiation and Assignment
- Declaration, Instantiation and Assignment
- Invocation of the 150 lb Dog’s makeNoise method.
- Static vs. Non-static (a.k.a. instance)
- Static methods are invoked using the class name, e.g. Dog.makeNoise();
- Instance methods are invoked using an instance name, e.g. maya.makeNoise();
- Static methods can’t access “my” instance variables, because there is no “me”.
- Why Static Methods?
- Some classes are never instantiated.
- public static void main(String[] args)
- Using Libraries (e.g. StdDraw, In): A useful library: The Princeton Standard Library
-
Project 0 (TODO: Test and Extra)
-
Week 2 (1/22-1/26) : References, Recursion, and Lists; SLLists, Nested Classes, Sentinel Nodes; DLLists, Arrays
- Lists1
- The Mystery of the Walrus
- Primitive Types (8: byte, short, int, long, float, double, boolean, char)
- Reference Types (everything else, including arrays, is a reference type)
- Parameter Passing: passing parameters obeys the same rule: simply copy the bits to the new scope(passing by value)
- Summary: there are 9 types of variables in Java: 8 primitive types and reference type.
- Instantiating Arrays
- Declaration and Instantiation of Arrays
- IntList and Linked Data Structures
- IntList, IntList size(recursive method), IntList iterativeSize(no recursive method), More Exercises
- Lists2: The SLList (“naked” linked lists like the IntList class are hard to use; SLList class acts as a middle man between user and raw data structure)
- Intro
- Access Control: using
private
keyword- Why Restrict Access? Hide implementation details from users of your class.
- Less for user of class to understand.
- Safe for you to change private methods(implementation).
- Car analogy:
- Public: Pedals, Steering Wheel; Private: Fuel line, Rotary valve.
- Despite the term ‘access control’:
- Nothing to do with protection against hackers, spies, and other evil entities.
- Why Restrict Access? Hide implementation details from users of your class.
- Nested Classes
- static: if IntNode class never try to use its outer class stuff, then you can make IntNode static.
- Adding More SLList Functionally
- .addLast(int x)
- .size()
- Caching: After implementing .addLast and .size, both of them are very slow. How to improve? Fast size()
- Solution: Maintain a special size variable that caches the size of the list.
- Caching: putting aside data to speed up retrieval.
- Sentinel Node (哨兵) : 去除特殊例子(比如 if x == null)的代码改进处理。
- Notes:
- I’ve renamed
first
to be sentinel; - sentinel is never null, always points to sentinel node.
- Sentinel node’s item needs to be some integer, but doesn’t matter what value we pick.
- Had to fix constructors and methods to be compatible with sentinel nodes.
- I’ve renamed
- Bottom line: Having a sentinel simplifies our
addLast
method.
- Notes:
- Invariants(Invariants make it easier to reason about code)
- Lists1
Methods | Non-Obvious Improvements |
---|---|
addFirst(int x) | #1: Rebranding: IntList -> IntNode |
getFirst | #2: Bureaucracy: SLList |
addLast(int x) | #3: Access Control: public -> private |
size() | #4: Nested Class: Bringing IntNode into SLList |
#5: Caching: Saving size as an int | |
#6: Generalizing: Adding a sentinel node to allow representation of the empty list. | |
#7: Looking back: .last and .prev allow fast removeLast (SLList -> DLList) | |
#8: Sentinel upgrade: Avoiding special cases with sentBack or circular list. Fancier Sentinel Node(s) |
-
How could we modify our list data structure so that addLast is also fast?
- Lists3: The DLList (Double Linked Lists): reverse pointers allow all operations (add, get, remove) to be fast.
- DLList(Naive) -> DLList(Double Sentinel) (use for proj1) -> DLList(Circular Sentinel) (proj1)
- Generic Lists
- Java allows us to defer type selection until declaration.
- In the .java file implementing your data structure, specify your “generic type” only once at the very top of the file.
- In .java files that use your data structure, specify desired type once:
- Write out desired type during declaration.
- Use the empty diamond
- Lists3: The DLList (Double Linked Lists): reverse pointers allow all operations (add, get, remove) to be fast.