C Sc 227 11-April Pracitce Quiz
Section Linked Structures
Use this singly-linked structure to answer questions 1-4
[pic]
1. What is the value of front.data? ______
2. What is the value of front.next.next.data? ______
3. What is the value of front.next.data? ___
4. What is the value of front.next.next.next? ______
5. Write the code that will generate the following linked structure.
[pic]
6. Draw a picture of the linked structure built from this code:
Node n1 = new Node("aaa");
n1.next = new Node("bbb");
n1.next.next = new Node("ccc");
n1.next.next.data = "fff";
7. Using the code in question 6, What happens with this code n1.next.next.next.data = "ggg";
8. Complete methods toString addLast as if it was in the LinkedList class began in lecture so it adds a new element at the end of a linked structure referred to by front. The following code should generate this picture of memory.
LinkedList list = new LinkedList();
list.addLast("First");
list.addLast("Second");
list.addLast("Third");
public class LinkList {
private class Node {
private E data;
private Node next;
public Node(E objectReference) {
data = objectReference;
}
public Node(E objectReference, Node nextReference) {
data = objectReference;
next = nextReference;
}
}
private Node front;
private int n;
public LinkList() {
front = null;
n = 0;
}
public void addFirst(E element) {
front = new Node(element, front);
n++;
}
public void addLast(String element) {
ANSWERS
1. What is the value of front.data? __"A"____
2. What is the value of front.next.next.data? __"C"____
3. What is the value of front.next.data? _"B"__
4. What is the value of front.next.next.next? _null_____
5. Write the code that will generate the following linked structure.
Node front = new Node("1st");
Node back = new Node("2nd");
front.next = back;
6. Draw a picture of the linked structure built from this code:
Node n1 = new Node("aaa");
n1.next = new Node("bbb");
n1.next.next = new Node("ccc");
n1.next.next.data = "fff";
[pic]
7. Null pointer exception
8. public void addLast(E element) {
if (isEmpty())
this.addFirst(element);
else {
Node ref = front;
while (ref.next != null)
ref = ref.next;
ref.next = new Node(element);
}
size++;
}
-----------------------
[pic]
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- april themes for toddlers
- c c international group
- april preschool themes lesson plans
- sat april 2018 qas
- april 2019 events anchorage
- april 2017 customs broker exam
- april preschool lesson plan themes
- auto loan rates april 2019
- army gpc form 17 2 april 2019
- april snow storms in massachusetts
- april 2019 calendar with holidays
- ford april 2019 incentives list