Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Immediately need help Priority Queue on C++, Please teach me how to type this pr

ID: 3923851 • Letter: I

Question

Immediately need help Priority Queue on C++, Please teach me how to type this programming and do not use handwriting.

This is Programming question:

Implement a Priority Queue(PQ) using an UNSORTED LIST. Use an array size of 10 elements. Use a circular array: Next index after last index is 0. Add the new node to next available index in the array. When you add an element, add 1 to index (hit max index, go to index 0). Test if array in full before you add. When you remove an element, from the list, move the following elements to the left to fill in the blank, etc ( Like prior program done with LISTS ).

Explanation / Answer

Programme:

public class ListPQueue<E>

{
    private ArrayList<E> elts;

    public ListPQueue()      { elts = new ArrayList<E>();

}
    public boolean isEmpty() { return elts.size() == 0;  

}
    public void add(E value) { elts.add(value);          

}

    public E peek()

{
        E min = elts.get(0); // minimum seen so far
        for(int i = 1; i < elts.size(); i++) {
            Comparable<E> val = (Comparable<E>) elts.get(i);
            if(val.compareTo(min) < 0) min = (E) val;
        }
        return min;
    }

    public E remove()

{
        E min = elts.get(0); // minimum seen so far
        int minPos = 0;           // position of min within elts
        for(int i = 1; i < elts.size(); i++) {
            Comparable<E> val = (Comparable<E>) elts.get(i);
            if(val.compareTo(min) < 0) { min = (E) val; minPos = i; }
        }
        elts.remove(minPos);
        return min;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote