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);
AI 摘要
- 文档名称
- 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
- 页数
- 12 页
- 上传者
- Uni24h
常见问题
此文档免费吗?
是的。“Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou”是免费的 — 只需登录并点击“下载”即可获取原始文件。
这份文档有多少页?
该文档共有 12 页,适用于课程 Lập trình Java。您可以在下载前进行在线预览。
我可以在下载前预览吗?
是的。您可以通过在线阅读器直接在本页面预览此文档,然后再决定是否下载。
Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
正在生成预览...
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);
阅读全文
- 文档名称
- 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
- 页数
- 12 页
- 上传者
- Uni24h
评论 (0)
暂无评论。快来抢沙发吧!
Misc.onclusion (Discussion 14-END) (Ôn tập cấu trúc dữ liệu) - Christine Zhou
Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
Giáo trình Lập trình Java
Inheritance (Discussion 4) (Kế thừa trong Java) - Christine Zhou
Asymptotic Analysis (Discussion 7) (Phân tích tiệm cận) - Christine Zhou
Chương 7.Cơ học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 6.Quang học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 5.Thuyết tương đối - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 4. Tán xạ ánh sáng - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 3.Phân cực ánh sáng - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
评论 (0)
暂无评论。快来抢沙发吧!