Linked List Searching Example

The program shown at the end of this web page solves the following problem:

Write a Java main program that determines whether or not various search terms are in a list of strings. The input will come from the command line as follows:

  1. an integer, n, that represents the number of strings in the list
  2. n strings representing the strings in the list
  3. an unspecified number of strings. For each string your program should determine if the string is in the list.

Write a search method that you call from your main program to perform the actual search. It should return true/false depending on whether or not it finds the string. Its parameters should include the array of strings and the string to be found.

Your main program should create a linked list to store the strings in the list, and then loop through the remaining strings on the command line, call the search method, and print the result using System.out.printf. Your program should print the string and either true/false. For example, the command:

   java search 3 brad nels james jim nancy brad nels
should produce the output:
   jim false
   nancy false
   brad true
   nels true
You should create a package called samplelist and create two classes named LinkedList and Node to complete this problem. LinkedList should implement a container object for a doubly-linked list that can store strings, and Node should be a class representing a node in the linked list.

Next create a class named that inserts items at the back of a LinkedList, and then tries to find the search terms in the linked list.

The Class Files