Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
Tài liệu thảo luận về con trỏ và danh sách liên kết (IntList) trong Java, bao gồm ôn tập và các bài tập về biểu diễn hộp và con trỏ, chèn, đảo ngược và dịch chuyển danh sách.
正在生成预览...
Discussion 2: Pointers Christine Zhou Agenda Announcements Review Worksheet Announcements Happy three-day weekend! HW1 due Friday 9/8 Proj0 due Tuesday 9/18 Get started ASAP! Labs are due at midnight on Fridays Discussion survey: tinyurl.com/czdisc2 Review: Defining Classes // class definition public class IntList { // instance variables int head; IntList tail; // constructors, which will create IntList objects public IntList() {...} public IntList(int value, IntList tail) {...} // you can create methods that use the instance variables! public void insert(int val) {...} public void removeLast() {...} } Review: Primitives and Reference Types Two types of values: primitives and reference types 8 primitive types: char, boolean, int, double, float, byte, short, long All others are reference types (Strings, self-defined classes like IntList) Pass-by-value When Java creates a primitive type value, it will create a box and store that primitive value in the box When Java creates a reference type value, it will create a box and store the pointer to the reference type value (the value in the box will be the address of the object in memory) Review: Box and Pointer Diagrams Will be very helpful in keeping track of everything! Small example with an int and a Potato object (with an int age and a String variety) Review: Box and Pointer Diagrams Let’s try a small example with the IntList we defined a few slides ago. Draw the B&P for the following code: IntList lst1 = new IntList(1, null); lst1 = new IntList(2, lst1); IntList lst2 = new IntList(3, null); lst2 = new IntList(4, lst2); lst2.head = lst1.head; lst2.tail = lst1.tail; Take the value living inside the box that we’re looking for, and then do the reassignment (pass-by-value of the box) 1. Boxes and Pointers Draw a box and pointer diagram to represent the IntLists after each statement. IntList L = IntList.list(1, 2, 3, 4); IntList M = L.tail.tail; IntList N = IntList.list(5, 6, 7);
… Tải file gốc để đọc toàn bộ tài liệu.
- 文档名称
- Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
- 学校 / 课程
- University of California, Berkeley · Lập trình Java
- 内容
- Tài liệu này giới thiệu về con trỏ trong Java, phân biệt kiểu dữ liệu nguyên thủy và tham chiếu, và hướng dẫn sử dụng sơ đồ Hộp và Con trỏ. Nó cung cấp các bài tập thực hành về thao tác trên danh sách liên kết như chèn, đảo ngược và dịch chuyển.
- 目录
- Agenda
- Announcements
- Review
- Worksheet
- Review: Defining Classes
- Review: Primitives and Reference Types
- Review: Box and Pointer Diagrams
- 1. Boxes and Pointers
- 2. Insertion
- 3. Reverse
- 4. Shifting a Linked List
- Doc.pages
- 12 页
- 上传者
- Giang Le
常见问题
Tài liệu này có miễn phí không?
Có. “Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou” miễn phí — bạn chỉ cần đăng nhập rồi bấm Tải xuống để lấy file gốc.
Tài liệu dài bao nhiêu trang?
Tài liệu gồm 12 trang, thuộc môn Lập trình Java. Bạn có thể xem trước online trước khi tải.
Tôi có thể xem trước trước khi tải không?
Có. Bạn xem trước tài liệu ngay trên trang này bằng trình đọc online, rồi quyết định tải về.

评论 (0)
暂无评论。快来抢沙发吧!