hi i have used three classes to make link list in java lean list as interface, Basic list got the constructor etc , and Demo basic test i need the function to be added in the demo basic list to complete the program.
the following code for classes are as follows:
leanlist
interface LeanList<ItemType>
{
public static final int MAX_LENGTH=10;
public boolean insertItem(ItemType newItem);
public boolean deleteItem();
public boolean advance();
public boolean retreat();
public boolean jumpTo(int pos);
public boolean validPos();
public int Length();
public ItemType getItem();
}
Basic List
public class BasicList <ItemType> implements LeanList <ItemType>
{
private int _pos= 0;
private int _len= 0;
private final ListNode _root = new ListNode((ItemType)null);
private ListNode currentNode = _root;
private ListNode previousNode;
public BasicList() {}
public boolean insertItem(ItemType newItem) {
if ((_pos<=0) || (_len== MAX_LENGTH))
return false;
ListNode newNode = new ListNode(newItem);
ListNode LeftNode = previousNode;
ListNode RightNode = currentNode;
currentNode = newNode;
previousNode = LeftNode;
LeftNode.next = newNode;
newNode.previous = LeftNode;
if(RightNode !=null) {
newNode.next = RightNode;
RightNode.previous = currentNode;
}
_len++;
return true;
}
public boolean ValidPos() {
return((_pos>=1 && (_pos<= _len))) ;
}
public boolean deleteItem() {
if((!validPos()) || (_len==0)) return false ;
ListNode leftNode = previousNode;
ListNode rightNode = currentNode.next;
leftNode.next = rightNode;
if(rightNode!= null)
rightNode.previous = leftNode;
currentNode = rightNode;
_len--;
return true;
}
public boolean advance() {
if(_pos == _len+1) return false;
return jumpTo (_pos+1);
}
public boolean retreat() {
if(_pos==0) return false;
return jumpTo(_pos-1);
}
public boolean jumpTo(int pos) {
if((_pos<0) || (pos>_len+1)) return false ;
currentNode = _root;
_pos=pos;
while (pos>0) {
previousNode = currentNode;
currentNode = currentNode.next;
_pos--;
}
return true;
}
public boolean validPos()
{
return ((_pos>=1 && (_pos<= _len)));
}
public ItemType getItem() {
if(currentNode==null)
return null;
return (ItemType) currentNode.itm;
}
public int Length() {
return _len;
}
public class ListNode
{
private ItemType itm;
private ListNode previous;
private ListNode next;
public ListNode(ItemType item){
this.itm = item;
}
public ListNode getPrevious() {
return previous;
}
public ListNode setPrevious(ListNode previous) {
return this.previous = previous;
}
public ListNode gotNext() {
return next;
}
public void setNext(ListNode next) {
this.next = next ;
}
public ItemType getIem() {
return itm;
}
}
public void display() {
ListNode node = _root;
while( (node = node.next)!= null)
System.out.println(node.itm);
System.out.println();
}
}
DemoBasic List plz help me in adding the required functions in this class.. thank you
public class DemoBasicTest
{
public static void main(String [] args){
BasicList<Integer> list = new BasicList<Integer>();
}
}