University of Kwazulu Natal: School of Mathematics, Statistics & Computer Science
University of Kwazulu Natal: School of Mathematics, Statistics & Computer Science
COMPUTER SCIENCE
WESTIVILLE CAMPUS
Practical III
Examiner: Mr E. Jembere
Duration: Open
Instructions
1. Go over this Practical paper in preparation for the Tutorial/Practical session on Tuesday,
22 August 2017.
2. Use the resource files in the file named Prac_III_Resources on the course page on Moodle.
The resource files include the following files; MyList.java, MyAbstractList.java,
MyArrayList.java and MyLinkedList.java.
3. For all your implementations involving a singly linked list, define your own Node
class(name SLLNode) with the following two constructors:
a. a no-argument constructor,
b. a two-argument constructor that takes a value and a reference to the next node
as arguments.
1. **(Add set operations in MyList) Define the following methods in MyList and implement them
in MyAbstractList:
/** Adds the elements in otherList to this list.
* Returns true if this list changed as a result of the call */
public boolean addAll(MyList<E> otherList);
1|Page
/** Retains the elements in this list that are also in otherList
* Returns true if this list changed as a result of the call */
public boolean retainAll(MyList<E> otherList);
Write a test program that creates two MyArrayLists, list1 and list2, with the initial values
{"Tom", "George", "Peter", "Jean", "Jane"} and {"Tom", "George", "Michael", "Michelle",
"Daniel"}, then perform the following operations:
3. **(Implement a doubly linked list) Define a class for a Doubly-Linked list node with the
following properties:
i. Three (3) class attributes value, next and previous to hold the value of the node, a
reference to the next node and a reference to the previous node respectively,
ii. a no-argument constructor, and
iii. a three-argument constructor DLLNode(E e, DLLNode nxt, DLLNode prev) ,
where nxt is a reference to the next node and prev is reference to the previous node.
Your doubly-linked list is also expected to implement the methods; add(), addFirst(E e),
addLast(E e), addLast(E e), add( int index, E e), removeFirst(), removeLast(), remove(int
index)
b. Write a test program to test the methods you implemented in Question (3.a)
2|Page
4. *Extend the implementation of MyLinkedList to implement a Circular-linked list. Name the
class MyCircularlinkedList. Your implementation should include the implementation of the
following methods
a. addFirst(E e),
b. addLast(E e),
c. removeFirst(),
d. removeLast().
----------------------------------------------------------------------------------------------------------------
3|Page