Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
Generating preview...
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.
Description
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 summary
- Document name
- Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
- School / Course
- University of California, Berkeley · Lập trình Java
- Content
- 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.
- Table of contents
- 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
- Pages
- 12 pages
- Uploaded by
- Uni24h
Frequently asked questions
Is this document free?
Yes. “Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou” is free — just sign in and click Download to get the original file.
How many pages is this document?
The document has 12 pages, for the course Lập trình Java. You can preview it online before downloading.
Can I preview before downloading?
Yes. You can preview this document right on this page with the online reader, then decide whether to download.
Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
Generating preview...
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);
Read full document
- Document name
- Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
- School / Course
- University of California, Berkeley · Lập trình Java
- Content
- 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.
- Table of contents
- 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
- Pages
- 12 pages
- Uploaded by
- Uni24h
Comments (0)
No comments yet. Be the first!
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
Comments (0)
No comments yet. Be the first!