package simulator;

import java.util.LinkedList;

/**
 * This is a queue implemented with a linked list. As a regular queue, 
 * its elements are ordered in a first-in-first-out(FIFO) manner.
 * 
 * @author Gabriela Marcu
 *
 * @param <E>
 */
public class MyQueue<E> {

	LinkedList<E> queue;
	
	public MyQueue()
	{
		queue = new LinkedList<E>();
	}
	
	public MyQueue(MyQueue<E> other)
	{
		this.queue = new LinkedList<E>(other.queue);
	}
	
	
	// Adds the element to the end of the queue, not allowing null elements.
	public void enqueue(E element)
	{
		queue.addLast(element);
	}
	
	// Returns and removes the first element of the queue.
	public E dequeue()
	{
		return queue.poll();
	}
	
	// Returns true if the queue is empty, false otherwise.
	public boolean isEmpty()
	{
		return queue.size() == 0;
	}
	
	public MyQueue<E> clone()
	{
		return new MyQueue<E>(this);
	}
}

