Advertisement
nate23nate23

mostlinks -done

Dec 1st, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. /*
  2.      * Name:Nate Wheeler
  3.      * Date:november 18, 2016
  4.      * Course Number: csc220
  5.      * Course Name: data structures
  6.      * Problem Number: hw08
  7.      * Email: nate23nate23@gmail.com
  8.      * Short Description of the Problem
  9.      * make spell-checker using a dictionary
  10.      */
  11. package compsci220;
  12.  
  13. public class MostRecentlyUsedLinkedList<E extends String> extends MyLinkedList<String>{
  14.    
  15.     public boolean contains(E e){
  16.         if(head == null)
  17.             return false;
  18.         Node<E> current=(compsci220.MyLinkedList.Node<E>) head;
  19.         while(current.next != null){
  20.             //comparing both elements
  21.             if(current.element.equals(e)){
  22.                 //removes the element of current by its index and places it in front of the list
  23.                 addFirst(remove(indexOf((String) current.element)));
  24.                 return true;
  25.             }
  26.             else {
  27.                 current=current.next;
  28.             }          
  29.         }
  30.         return false;      
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement