Quiz 2 Worksheet for CMSC 132: LinkedList Exercises, Quizzes of Computer Science

Information about quiz 2 for the cmsc 132 course, including the quiz date, format, and covered topics. Students are required to complete several exercises related to implementing methods for a linkedlist class. The exercises cover creating an empty list, adding strings to the beginning and end, printing list elements, removing the last node, finding a string in the list, inserting a string before a target, and filtering the list based on string length. Solutions will not be provided, but students can discuss their answers with the ta or instructor during office hours.

Typology: Quizzes

Pre 2010

Uploaded on 02/13/2009

koofers-user-qej-1
koofers-user-qej-1 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 132 Quiz 2 Worksheet
The second quiz for the course will be on Monday, Feb 19, 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 e xercises 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 Node {
String data;
Node next;
}
public class LinkedList {
Node head;
}
1. Define a constructor for the LinkedList class that creates an empty list.
2. Define a method called addFirst that adds a String to the beginning of the list.
3. Define a method called addLast that adds a String 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 print that prints the String data of each node in the list.
6. Implement a method named removedLastNode that removes the last node from the list.
7. Define a method named find that has as parameter a String reference. The method will
return true if the String is found in the list and false otherwise. Use the equals method to
compare Strings.
8. Define a method called insert that has the following prototype:
public boolean insert(String entry, String target);
The method will look for the first instance of target in the list and will insert entry before
that instance. 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 LinkedList filter(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 list.

Partial preview of the text

Download Quiz 2 Worksheet for CMSC 132: LinkedList Exercises and more Quizzes Computer Science in PDF only on Docsity!

CMSC 132 Quiz 2 Worksheet

The second quiz for the course will be on Monday, Feb 19, 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 Node {

String data;

Node next;

public class LinkedList {

Node head;

  1. Define a constructor for the LinkedList class that creates an empty list.
  2. Define a method called addFirst that adds a String to the beginning of the list.
  3. Define a method called addLast that adds a String 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 print that prints the String data of each node in the list.
  6. Implement a method named removedLastNode that removes the last node from the list.
  7. Define a method named find that has as parameter a String reference. The method will return true if the String is found in the list and false otherwise. Use the equals method to compare Strings.
  8. Define a method called insert that has the following prototype:

public boolean insert(String entry, String target);

The method will look for the first instance of target in the list and will insert entry before that instance. 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.

  1. Define a method called filter that has the following prototype:

public LinkedList filter(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 list.