In: Computer Science
java method for dequeue
write the “dequeue” method for a queue of type double. If the queue is empty return 0.0. Make sure to change the links properly ensure that the data structure remains a queue.
use the code provided below
public class Q04 
{
        public class ListNode//Public for testing purposes
        {
                public double data;
                public ListNode link;
                public ListNode(double aData, ListNode aLink)
                {
                        data = aData;
                        link = aLink;
                }
        }
        public ListNode head;//Public for testing purposes
        public ListNode tail;//Public for testing purposes
                
        public double dequeue()
        {
//------------------------------------------------------------------------------------  
                //Write your code here
                
                
                
                
                
                
                
                
                
                
                
                
        }//Do not alter 
        //Test your code here. You may alter this as needed.
        public static void main(String[] args)
        {
                //Example
                Question04 intQ = new Question04();
                intQ.head = intQ.new ListNode(0, 
                                                        intQ.new ListNode(1, 
                                                                        intQ.new ListNode(2,
                                                                                        intQ.new ListNode(3,
                                                                                                        intQ.new ListNode(4,null)))));
                //Printing Results
                System.out.println(intQ.dequeue());
        }
        //--------------------------------------------------------------------------------
}
public class Question04 {
    public class ListNode//Public for testing purposes
    {
        public double data;
        public ListNode link;
        public ListNode(double aData, ListNode aLink) {
            data = aData;
            link = aLink;
        }
    }
    public ListNode head;//Public for testing purposes
    public ListNode tail;//Public for testing purposes
    public double dequeue() {
//------------------------------------------------------------------------------------
        if (head == null) {
            return 0;
        } else {
            double result = head.data;
            head = head.link;
            if (head == null)
                tail = null;
            return result;
        }
    }//Do not alter
    //Test your code here. You may alter this as needed.
    public static void main(String[] args) {
        //Example
        Question04 intQ = new Question04();
        intQ.head = intQ.new ListNode(0,
                intQ.new ListNode(1,
                        intQ.new ListNode(2,
                                intQ.new ListNode(3,
                                        intQ.new ListNode(4, null)))));
        //Printing Results
        System.out.println(intQ.dequeue());
    }
    //--------------------------------------------------------------------------------
}