import java.util.*; public class MyLinkedListQueue { class Node { public Object data; public Node next; private Node first; public MyLinkedListQueue() { first = null; } public Object peek() { if(first==null) { throw new NoSuchElementException(); } return first.data; } public void enqueue(Object element) { Node newNode = new newNode(); newNode.data = element; newNode.next = first; first = newNode; } public boolean isEmpty() { return(first==null); } public int size() { int count = 0; Node p = first; while(p ==! null) { count++; p = p.next; } return count; } } } Hello, I am getting an error message when I execute this program. This is what I get: MyLinkedListQueue.java:11: error: invalid method declaration; return type required public MyLinkedListQueue() ^ 1 error I also need to have a dequeue method in my program. It is very similar to the enqueue method. I'll appreciate the help, Thanks!
import java.util.*;
public class MyLinkedListQueue
{
class Node
{
public Object data;
public Node next;
private Node first;
public MyLinkedListQueue()
{
first = null;
}
public Object peek()
{
if(first==null)
{
throw new NoSuchElementException();
}
return first.data;
}
public void enqueue(Object element)
{
Node newNode = new newNode();
newNode.data = element;
newNode.next = first;
first = newNode;
}
public boolean isEmpty()
{
return(first==null);
}
public int size()
{
int count = 0;
Node p = first;
while(p ==! null)
{
count++;
p = p.next;
}
return count;
}
}
}
Hello, I am getting an error message when I execute this program. This is what I get:
MyLinkedListQueue.java:11: error: invalid method declaration; return type required
public MyLinkedListQueue()
^
1 error
I also need to have a dequeue method in my program. It is very similar to the enqueue method.
I'll appreciate the help, Thanks!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps