



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A final exam for a university-level java programming course, covering topics such as linked lists, sorting algorithms, recursion, and testing. It includes sample code, problem-solving exercises, and assertion statements.
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




CIS3023 Final Exam Summer 2008 SAMPLE Name: ______________________
1 (15). You have the following definitions for LinkedList and Node:
public class LinkedList { protected Node head;
public Node getFirst() { return head; }
public void setFirst(Node head) { this .head = head; } }
class Node { private Object element; private Node next;
public Node(Object element, Node next) { this .element = element; this .next = next; }
public Object getElement() { return element; }
public Node getNext() { return next; }
public void setNext(Node next) { this .next = next; } }
Complete the method below:
// This method does a linear search over a linked list and returns the index of the element // or -1 if the element is not in the list. public int doLinearSearch(LinkedList list, Object target) {
Index: 0 1 2 3 4 5 6 Value: 9 3 1 8 5 7 3
Part B: Sort the same list using MergeSort. Show all steps. Is this sort in-place? Why?
4 (15). You want to remove all duplicate words from a String. Assume that the String has only words and spaces, and has no punctuation. You must use an ArrayList to solve this problem. Remember to parameterize your ArrayList (using bracket notation). Complete the method below.
public String removeDuplicates(String words) {
5 (15). You have the following recursive method that calculates the nth Fibonacci number:
public int fib(int num) { if (num == 1 || num == 2) { return 1; } else { return fib(num – 1) + fib(num – 2); } }
Convert this into a method that uses a stack instead of making recursive calls.
public int fib(int num) {
7 (5). Explain what it means for one thread to join another thread.