Docsity

6 Problems on Java Programs of Method - Study Guide | CMSC 132, Study notes of Computer Science

Toggle sidebar
bg1
LinkedList Exercise
The following Java class definitions will be used for the exercises below.
public class MyLinkedList {
private class Node {
private Object data;
private Node next;
public Node(Object data) {
this.data = data;
next = null;
}
}
}
IMPORTANT: You may not use the Java API LinkedList class.
1. Implement a MyLinkedList constructor that defines an empty linked list.
2. Implement a method named isEmpty that determines whether a list is empty.
3. Implement a method named size that returns the number of elements in the list.
4. Implement a MyLinkedList constructor that has the following signature:
MyLinkedList(ArrayList<Object> dataArray)
The constructor will initialize the linked list using the data elements from the array.
5. Implement a method named duplicate that creates a duplicate (shallow copy) of the list.
6. Would it be possible to implement a method that determines whether a list is full?

Partial preview of the text

Download 6 Problems on Java Programs of Method - Study Guide | CMSC 132 and more Study notes Computer Science in PDF only on Docsity!

LinkedList Exercise

The following Java class definitions will be used for the exercises below. public class MyLinkedList { private class Node { private Object data; private Node next; public Node(Object data) { this.data = data; next = null; } } }

IMPORTANT: You may not use the Java API LinkedList class.

  1. Implement a MyLinkedList constructor that defines an empty linked list.
  2. Implement a method named isEmpty that determines whether a list is empty.
  3. Implement a method named size that returns the number of elements in the list.
  4. Implement a MyLinkedList constructor that has the following signature: MyLinkedList(ArrayList dataArray) The constructor will initialize the linked list using the data elements from the array.
  5. Implement a method named duplicate that creates a duplicate (shallow copy) of the list.
  6. Would it be possible to implement a method that determines whether a list is full?