Hello I do Singly-Linked Lists. But i have probelm. I canīt do some methods (empty methods in my code). How can i do it?
Thank you.
My code:
Main class:
Item class:public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Pomoc o1 = new Pomoc(); System.out.println(o1.isEmpty()); o1.addFirst(10); o1.addFirst(20); o1.addFirst(25); System.out.println(o1.isEmpty()); System.out.println(o1.getFirst()); } }
Method classpublic class Item { private int data; private Item next; private Item previous; public void setData(int data) { this.data=data; } public int getData() { return data; } public void setNext(Item next) { this.next=next; } public Item getNext() { return next; } public void setPrevious(Item previous) { this.previous=previous; } public Item getPrevious() { return previous; } }
public class Pomoc { private Item act; private Item first; public boolean isEmpty() { return first == null; } public void addFirst(int o) { Item newItem = new Item(); newItem.setData(o); newItem.setNext(first); first = newItem; } public void removeFirst() { if(first==null) { System.err.println("Seznam je prazdny"); } else { this.first=first; } if(act==first) { act = null; } } public int getFirst() { return first.getData(); } public void setActFirst() { act=first; } public void setActNext() { Item actNext = new Item(); actNext.setPrevious(act); act = actNext; } public void removeAfterAct() { act.setNext(act); } public void addAfterAct(int i) { act.setData(i); act.setNext(act); } public int getAct() { return act.getData(); } public int getSize() { } }