Last active
April 28, 2016 09:54
-
-
Save LukeMcNemee/6f2ba226b087ba4b083f17466b1ca3fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
/** | |
* | |
* @author lukemcnemee | |
*/ | |
public class MyList<T> { | |
private Member<T> first; | |
private Member<T> last; | |
public boolean contains(T t) { | |
Member current = first; | |
while (current != null) { | |
if (current.equals(t)) { | |
return true; | |
} | |
current = current.getNext(); | |
} | |
return false; | |
} | |
public boolean add(T t) { | |
Member add = new Member(t); | |
if (contains(t)) { | |
return false; | |
} else { | |
if(last != null && first != null){ | |
last.setNext(add); | |
add.setPrevious(last); | |
last = add; | |
} else if(first == null){ | |
first = add; | |
} else { | |
last = add; | |
first.setNext(add); | |
last.setPrevious(first); | |
} | |
return true; | |
} | |
} | |
public boolean remove(T t) { | |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
} | |
public int size() { | |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
} | |
public void clear() { | |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
} | |
public void print() { | |
Member current = first; | |
System.out.println("My List: {"); | |
while (current != null) { | |
System.out.println(current.toString()); | |
current = current.getNext(); | |
} | |
System.out.println("}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment