Hello,I've recently started studying Java, and I've encountered some problems with lists. There's pretty much close to none information about this where I am studying at, so I would be really grateful if someone could create these 3 methods for me, since I would have a great example to use later on. I have to create the 3 methods add(int k, Data data), set(int k, Data data), remove(int k) . Here's the code I have : ( although I think the main part needed for these methods is:
private Node<Data> first;
private Node<Data> last;
private Node<Data> current;
package studijosKTU; public class ListKTU<Data> implements ListADT<Data> { private Node<Data> first; private Node<Data> last; private Node<Data> current; private int size; /** * Constructs an empty list. */ public ListKTU() { } public boolean add(Data data) { // adds an element to the end of the list if(data==null) return false; // doesnt take null objects if (first == null) { first = new Node<Data>(data, first); last = first; } else { Node<Data> e1 = new Node(data, null); last.next = e1; last = e1; } size++; return true; } public boolean add(int k, Data data){ // inserts before k position if(data==null) return false; // doesnt take null bojects if (k<0||k>=size)return false; // returns null if k isn't correct. throw new UnsupportedOperationException ("Have to create this one"); public int size() { return size; } public boolean isEmpty() { return first == null; } public void clear() { size = 0; first = null; last = null; current = null; } public Data get(int k){ // returns the value of k if (k<0||k>=size)return null; current=first.findNode(k); return current.element; } public Data set(int k, Data data){ // sets the value of element k if(data==null) return null; throw new UnsupportedOperationException ("Have to create this one"); } public Data getNext(){ if(current==null) return null; current=current.next; if(current==null) return null; return current.element; } public Data remove(int k) { throw new UnsupportedOperationException ("Have to create this one"); } class Node<Data> { // class that ensures incapsulation public Data element; public Node<Data> next; Node(Data data, Node<Data> next) { this.element = data; this.next = next; } public Node<Data> findNode(int k){ Node<Data> e=this; for(int i=0;i<k;i++){ e=e.next; } return e; } } }