Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package comp1406t8;
- /** A linked list implementation for the list ADT that stores _strings
- *
- * Represents a list X0, X1, X2, ..., Xn-1 of Strings
- */
- public class LList extends LinkedList{
- /** Creates an empty linked list */
- public LList(){super();}
- /** Creates a linked list with a single item (X0)
- *
- * @param s is string X0 in the created list of size 1.
- */
- public LList(String s ){
- super(s);
- }
- @Override
- public String removeFront() {
- head = head.next;
- size-=1;
- return null;
- }
- @Override
- public String remove(int position) {
- if (position >= size) return null;
- size-=1;
- Node prev = head;
- Node current = head.next;
- for (int i=2; i<=position; i++) {
- prev = current;
- current = current.next;
- }
- prev.next = current.next;
- return null;
- }
- @Override
- public int find(String d) {
- int index = 0;
- Node next = head;
- while (next != null) {
- if (next.getData().equals(d)) return index;
- next = next.next;
- index++;
- }
- return -1;
- }
- @Override
- public boolean set(int position, String d) {
- Node next = head;
- for (int i=1; i<= position; i++) {
- next = next.next;
- }
- next.setData(d);
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement