Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
Génération de l'aperçu...
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);
Résumé IA
- Nom du document
- Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
- École / Cours
- University of California, Berkeley · Lập trình Java
- Contenu
- 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 des matières
- 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
- Téléversé par
- Uni24h
Foire aux questions
Ce document est-il gratuit ?
Oui. « Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou » est gratuit — il suffit de vous connecter et de cliquer sur Télécharger pour obtenir le fichier original.
Combien de pages compte ce document ?
Le document contient 12 pages, pour le cours Lập trình Java. Vous pouvez le prévisualiser en ligne avant de le télécharger.
Puis-je prévisualiser avant de télécharger ?
Oui. Vous pouvez prévisualiser ce document directement sur cette page avec le lecteur en ligne, puis décider de le télécharger ou non.
Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
Génération de l'aperçu...
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);
Lire le document entier
- Nom du document
- Pointers (Discussion 2) (Con trỏ và danh sách liên kết) - Christine Zhou
- École / Cours
- University of California, Berkeley · Lập trình Java
- Contenu
- 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 des matières
- 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
- Téléversé par
- Uni24h
Commentaires (0)
Aucun commentaire pour le moment. Soyez le premier !
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
Commentaires (0)
Aucun commentaire pour le moment. Soyez le premier !