X700: LinkedQueueEnqueue

For the question below, assume the following implementation of LinkedQueue:


public static final class LinkedQueue<T> implements QueueInterface<T> {
    private Node firstNode;
    private Node lastNode;

    public LinkedQueue() {
        firstNode = null;
        lastNode = null;
    }


    @Override
    public T getFront() {
        if (isEmpty()) {
            return null;
        }
        return firstNode.getData();
    }


    @Override
    public boolean isEmpty() {
        return firstNode == null;
    }


    @Override
    public void clear() {
        firstNode = null;
        lastNode = null;

    }

    public class Node{
        private T data; // Entry in bag
        private Node next; // Link to next node

        public Node(T dataPortion) {
            this(dataPortion, null);
        } // end constructor


        public Node(T dataPortion, Node nextNode) {
            data = dataPortion;
            next = nextNode;
        } // end constructor


        public T getData() {
            if (data != null) {
                return data;
            }
            return null;
        }


        public Node getNext() {
            return next;
        }


        public void setNext(Node newNext) {
            next = newNext;
        }

} // end LinkedQueue

Below, finish creating the enqueue method that has been started for you.

Your Answer:

Feedback

Your feedback will appear here when you check your answer.