** Math Video Game! Play Decimals in Space! Use your reflexes & mathematical knowledge to shoot the right rocks!


A+    A−    B  
Home
Algebra
Math Games
Geometry
Private Tutors
Interactive
Trigonometry
Jobs
Teacher Resources
On Facebook



AddThis Social Bookmark Button

Linked Lists

What you should know for first test

Some Possibley Suprising Examples of Parameterized Types

 
Valid
LinkedList<Comparable> f = new LinkedList<Comparable>();
Comparable[] comparableArray = new String[8];
Not acceptable
ArrayList<Comparable> f2 = new ArrayList<String>();
  • Exercise 1 : Using only the public interface of the linkedList class, write a method
    public static void downsize(LinkedList<String> staff)
    that removes ever other employee from a linked List. (Idea taken from Cay Horstmann's Java Concepts for AP Computer Science book)


    solution


  • Exercise 2 : Using only the public interface of the linkedList class, write a method
    public static void reverse(LinkedList<String> staff)
    that reverses the entire list. (Idea taken from Cay Horstmann's Java Concepts for AP Computer Science book):
  • Exercise 3: Add a method size() to our linkedList class that computes the number of elements in the list, by following links and count theelements unti the end of the lis is reached.
  • Exercise 4: The Linked list class in the standard library has an add method that allows efficient insertion at the end of the list. Implement this method (addLast()) for our pared down version of LinkedList class. Add an instance field to the linked list class that points to the last node in the list. Make sure that the other mutator methods update that field.
  • Exercise 5: Repeat the prior exercise but use a different implementation strategy. Remove the reference to the first node in the LinkedList class and make the next reference of the last node point to the first node, so that ll nodes forma cycyle. This is known as a circular linked list.
  • Exercise 6: Write method firstMin() that determines the value of the smallest item of type comparable in its list parameter and returns a pointer to the first node in the list that contains that value. (If the list is empty, firstMin returns null.) Remember that it's ok to declare a LinkedList as follows:
    LinkedList<Comparable> listOfComprables = new LinkedList<Comparable>();
    Note however, the following is illegal
     LinkedList<Comparable> f = new LinkedList<String>();
    For example, if L and p are ListNode references:
  • Exercise 7: Design and implement an insertion sort that operates on a linked list of nodes that each contain an integer.
  • Exercise 8: Design and implement a Selection sort that operates on a linked list of nodes that each contain an integer.
  • Exercise 9: Create a class called Palindrome. This class should have a method isPalindrome() that uses two linear linked lists to determine whether or not a String is a palindrome. Below is a reminder on how to use a JOptionPane. Make sure you import javax.swing.JOptionPane.
       String word= JOptionPane.showInputDialog("Type in a potential palindrome");
    


    solution


Linked listcode

Top
AddThis Social Bookmark Button