public class Node {
private Object element;
private Node next;
public Node()
{
this(null,null);
}
public Node(Object e, Node n)
{
element = e;
next = n;
}
public void setElement(Object newElement)
{
element = newElement;
}
public void setNext(Node newNext)
{
next = newNext;
}
public Object getElement()
{
return element;
}
public Node getNext()
{
return next;
}
}
################################################
public class Employee {
private int age,empNum;
private String fName, lName;
public Employee(int empNum, String fName, String lName, int age)
{
this.age = age;
this.empNum = empNum;
this.fName = fName;
this.lName = lName;
}
public String getName()
{
String joinName;
joinName = fName + lName;
return joinName;
}
public int getAge()
{
return age;
}
public int getEmpNum()
{
return empNum;
}
@Override
public String toString()
{
return empNum+ "\t" + fName+ " " + lName+ "\t" + age + "\n";
}
}
##################################################
public class LinkedQueue
{
private Node head, tail;
private int qSize;
public LinkedQueue()
{
head = tail = null;
qSize = 0;
}
public int size()
{
return qSize;
}
public Node getTail()
{
return tail;
}
public boolean isEmpty()
{
return ( head==tail );
}
public Object front() throws QueueEmptyException
{if (isEmpty())
throw new QueueEmptyException("Queue is empty");
else
return head.getElement();
}
public void append(Object obj)
{
Node node = new Node();
node.setElement(obj);
node.setNext(null);
if(qSize == 0)
head = node;
else
tail.setNext(node);
tail = node;
qSize++;
}
public Object serve()throws QueueEmptyException
{
Object obj;
if(qSize == 0)
throw new QueueEmptyException("Queue is empty");
else
{
obj = head.getElement();
head = head.getNext();
qSize--;
}
if(qSize == 0)
tail = null;
return obj;
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE