I have been working on a deque (double ended que) class. I still have a lot of work to do on all of the methods but want to be able to test what I code as I go. I am getting an Exception in thread "main" java.lang.NoSuchMethodError: main. I would appreciate any help in fixing this.
Thanks in advance, here is my code:
class DNode<E>
{
private E data;
private DNode<E> lLink, rLink;
public DNode(E iData, DNode<E> lefLink, DNode<E> riteLink)
{
data = iData;
rLink = riteLink;
lLink = lefLink;
}
public E getData()
{return data;}
public void setData(E aData)
{data = aData;}
public DNode<E> getRightLink()
{return rLink;}
public void setRightLink(DNode<E> righty)
{rLink = righty;}
public DNode<E> getLeftLink()
{return lLink;}
public void setLeftLink(DNode<E> lefty)
{lLink = lefty;}
public void addNodeAfter(E item)
{rLink = new DNode<E>(item, this, rLink);}
public void removeNodeAfter()
{rLink = rLink.getRightLink();}
}
class Deque<E>
{
private int manyNodes = 0;
private DNode<E> front, rear;
public Deque()
{
manyNodes = 0;
front = null;
rear = null;
}
public boolean isEmpty()
{return (manyNodes == 0);}
public void addAtEnd(E item)
{
if(isEmpty())
{
front.addNodeAfter(item);
rear = front;
}
else
{
rear.addNodeAfter(item);
rear = rear.getRightLink();
}
manyNodes++;
}
public void addtAtFront(E item)
{
if(isEmpty())
{
front.addNodeAfter(item);
rear = front;
}
else
{
front.addNodeAfter(item);
}
}
public void removeFirst() throws NoSuchFieldException
{
if(manyNodes == 0)
throw new NoSuchFieldException();
front.removeNodeAfter();
}
public void removeLast() throws NoSuchFieldException
{
if(manyNodes == 0)
throw new NoSuchFieldException("Ya dun goofed");
rear.removeNodeAfter();
}
public void print()
{
DNode<E> trace;
for(trace = front; trace.getRightLink() != null; trace = trace.getRightLink())
System.out.println(trace.getData());
}
}
class DequeRun
{
public static void main(String[] args)
{
Deque<String> test1 = new Deque<String>();
test1.addAtEnd("Ryan");
test1.addAtEnd("Mike");
test1.print();
}
}
将您的DequeRun设为公开,否则jvm将无法在其中找到main方法
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.