Download presentation
Presentation is loading. Please wait.
Published byΌσιρις Αντωνόπουλος Modified over 5 years ago
1
A3 is due after the break, but start on it NOW
Read HyperText entry on Study/work habits When given new tasks to get done, Procrastinate right from day one. You think that's not fine? It gives you more time To catch up at last as you're done.
2
Assignment A3: Linked Lists
Idea: maintain a list (2, 5, 7) like this: 2 a1 a6 v next 5 a6 a8 v next 7 a8 null v next h a1 This is a singly linked list To save space, we write names like a6 instead of 2
3
How to insert a node at the beginning
2 a1 a6 v next 5 a6 a8 v next 7 a8 null v next h a1 (2, 5, 7) h a3 2 a1 a6 v next 5 a8 7 null 8 (8, 2, 5, 7) 3
4
How to remove successor of a node in the middle
2 a1 a6 v next 5 a6 a2 v next 8 a2 a8 v next 7 a8 null v next h a1 k a6 (2, 5, 8, 7) h a1 2 a6 v next 5 a8 7 null 8 a2 k (2, 5, 7) 4
5
Assignment A3: Generics
public class LinkedList { void add(Object elem) {…} Object get(int index) {…} } Values of linked list are of class Object public class LinkedList<E> { void add(E elem) {…} E get(int index) {…} } You can specify what type of values ns = new LinkedList<Integer>(); ns.add("Hello"); // error ns.add(5); String s = ns.get(0); // error int n = ns.get(0); ss = new LinkedList<String>(); ss.add("Hello"); ss.add(5); // error String s = ss.get(0); int n = ss.get(0); // error
6
Assignment A3: Inner class
public class DList<E> { private Node first; … public E first() { return first.val; } … private class Node { private Node prev; private E val; } } field method class Outer class can and should use fields of class Node, even though they are private.
7
Quiz Name _________ Netid _________ Write the steps in evaluating the new expression new C(“b”) Write the steps in evaluating the new expression Write the steps in executing a method call. You need to know these: To answer questions about Java To help debug programs For the prelim In a constructor, do I have to store 0 in an int field? When is space allocated for a local variable?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.