DOC PREVIEW
UMD CMSC 132 - Quiz 2 Worksheet

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CMSC 132 Quiz 2 Worksheet The second quiz for the course will be on Wednesday, Feb 27, during your lab session. The following list provides more information about the quiz: - The quiz will be a written quiz (no computer). - Closed book, closed notes quiz. - Answers must be neat and legible. We recommend that you use pencil and eraser. The following exercises cover the material to be included in this quiz. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with the TA or instructor during office hours. We strongly recommend you do not use Eclipse to write the code associated with these exercises. Try to answer the exercises in a piece of paper and then use Eclipse to verify your solutions. This approach will better prepare you for the quiz. You cannot use any Java API class (except String) during the implementation of the methods below. Exercises Implement the methods below based on the following Java class definitions. public class LinkedList<T> { public class Node { private T data; private Node next; public Node(T data) { this.data = data; next = null; } } Node head; } 1. Define a constructor for the LinkedList class that creates an empty list. 2. Define a method called addFirst that adds an element to the beginning of the list. 3. Define a method called addLast that adds an element to the end of the list. 4. Define a method named size that returns the number of nodes in the list. 5. Implement a method named toString() that returns a String with the data component of each node in the list. 6. Implement a method named removeLastElement that removes the last element from the list. 7. Define a method named find that has as parameter an element of type T. The method will return true if an element equal to T is found in the list and false otherwise. You can assume the appropriate equals method has been defined for elements of type T. 8. Define a method called delete that has the following prototype: public boolean delete(T target); The method will delete the first instance of target in the list. The method will return true if a target instance is found and false otherwise. The list should not be modified if a target instance is not found.9. Define a method called filter that has the following prototype: public static LinkedList<String> filter(LinkedList<String> L, int maxLength); The method will return a new LinkedList with nodes containing only strings that are shorter or equal to maxLength. The method should not modify the original


View Full Document

UMD CMSC 132 - Quiz 2 Worksheet

Documents in this Course
Notes

Notes

8 pages

Recursion

Recursion

12 pages

Sorting

Sorting

31 pages

HTML

HTML

7 pages

Trees

Trees

19 pages

HTML

HTML

18 pages

Trees

Trees

19 pages

Honors

Honors

19 pages

Lecture 1

Lecture 1

11 pages

Quiz #3

Quiz #3

2 pages

Hashing

Hashing

21 pages

Load more
Download Quiz 2 Worksheet
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Quiz 2 Worksheet and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Quiz 2 Worksheet 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?