Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package comp1406t8;
  2.  
  3. /** A linked list implementation for the list ADT that stores _strings
  4. *
  5. * Represents a list X0, X1, X2, ..., Xn-1 of Strings
  6. */
  7. public class LList extends LinkedList{
  8.  
  9. /** Creates an empty linked list */
  10. public LList(){super();}
  11.  
  12. /** Creates a linked list with a single item (X0)
  13. *
  14. * @param s is string X0 in the created list of size 1.
  15. */
  16. public LList(String s ){
  17. super(s);
  18. }
  19.  
  20. @Override
  21. public String removeFront() {
  22. head = head.next;
  23. size-=1;
  24. return null;
  25. }
  26.  
  27. @Override
  28. public String remove(int position) {
  29. if (position >= size) return null;
  30. size-=1;
  31. Node prev = head;
  32. Node current = head.next;
  33. for (int i=2; i<=position; i++) {
  34. prev = current;
  35. current = current.next;
  36. }
  37. prev.next = current.next;
  38. return null;
  39. }
  40.  
  41. @Override
  42. public int find(String d) {
  43. int index = 0;
  44. Node next = head;
  45. while (next != null) {
  46. if (next.getData().equals(d)) return index;
  47. next = next.next;
  48. index++;
  49. }
  50. return -1;
  51. }
  52.  
  53. @Override
  54. public boolean set(int position, String d) {
  55. Node next = head;
  56. for (int i=1; i<= position; i++) {
  57. next = next.next;
  58. }
  59. next.setData(d);
  60. return false;
  61. }
  62.  
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement